how to pass structure variables
Am having a set of structure variable in one form, i want to use that structure variable as a global variables. i need to use those structure vari开发者_开发问答able in through out my whole application, how to use structure as global variable??
am using C#..
Put your structure variables as static members of a static helper class.
What you're looking for is a singleton class. Here is an example.
public class SingletonClass
{
#region Singleton instance
private static SingletonClass _instance;
public static SingletonClass Instance
{
get { return _instance ?? (_instance = new SingletonClass()); }
}
#endregion
#region Contructor
/// <summary>
/// Note that your singleton constructor is private.
/// </summary>
private SingletonClass()
{
// Initialize your class here.
}
#endregion
#region Public properties
// Place your public properties that you want "Global" in here.
public enum SomeEnumTypes
{
Type1,
Type2,
Type3
}
public int SomeMeasurements { get; set; }
public string SomeID { get; set; }
#endregion
}
So when you need this global class, just call on it like so:
var currentMeasurements = SingletonClass.Instance.SomeMeasurements;
Have fun.
精彩评论