如何传递结构变量
答
将您的结构变量作为静态辅助类的静态成员。
答
您正在寻找的是单身课程。这是一个例子。
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
}
所以,当你需要这个全球一流的,只需调用它像这样:
var currentMeasurements = SingletonClass.Instance.SomeMeasurements;
有乐趣。
在什么编程语言? – 2010-05-04 02:52:16
正在使用c#lang .. – 2010-05-04 03:21:22