2010-05-04 64 views
1

我在一种形式中有一组结构变量,我想将该结构变量用作全局变量。我需要在整个应用程序中使用这些结构变量,如何将结构用作全局变量?如何传递结构变量

正在使用C#..

+0

在什么编程语言? – 2010-05-04 02:52:16

+0

正在使用c#lang .. – 2010-05-04 03:21:22

回答

0

将您的结构变量作为静态辅助类的静态成员。

0

您正在寻找的是单身课程。这是一个例子。

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; 

有乐趣。