views:

56

answers:

2

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 variable in through out my whole application, how to use structure as global variable??

am using C#..

A: 

Put your structure variables as static members of a static helper class.

SKINDER
A: 

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.

Tri Q