Is there a way to store temporary list values ​​in C # 4.5?

I need to store the values ​​of a list non-persistently and I need to get the values ​​of that list in another C # class. the procedure is similar, session in Asp.net. Someone please share a few thoughts on this idea.

Here is my code:

Class1.cs:

    ObservableCollection<SampleEntityList> zoneList = new ObservableCollection<SampleEntityList>();
    ObservableCollection<SampleEntityList> ztowList = new ObservableCollection<SampleEntityList>();

      

I need to store these 2 list values ​​in some place locally and I need to go to those 2 list values ​​in a different class .. so anyway, I would rather not go as a constructor. I need to store these two rundown values ​​locally.

class2.cs:

??

I tried this code:

Created a new static class to set the property. What's more, I cannot access properties outside of the class.

Here's my code:

static class GlobalTempStorageVariable
{

    ObservableCollection<SampleEntityList> zoneListGlobal
                                    = new ObservableCollection<SampleEntityList>();
    ObservableCollection<SampleEntityList> ztowListGlobal
                                    = new ObservableCollection<SampleEntityList>();


    public static ObservableCollection<SampleEntityList> CurrentListOfInventories
    {
        get { return zoneListGlobal; }
        set { zoneListGlobal = value; }
    }

    public static ObservableCollection<SampleEntityList> CurrentSelectedInventories
    {
        get { return ztwoListGlobal; }
        set { ztwoListGlobal= value; }
    }

  }

      

But this code doesn't work. Also I cannot access CurrentListOfInventories and CurrentSelectedInventories outside of the class.

Class1.cs:

   GlobalTempStorageVariable. ???(its not showing the property)..

      

Any help would be appreciated.

+3


source to share


2 answers


A static property cannot access a non-static field, zoneListGlobal and ztowListGlobal must also be static in order to be accessible by their properties:



static class GlobalTempStorageVariable
{
    static ObservableCollection<SampleEntityList> zoneListGlobal
                                    = new ObservableCollection<SampleEntityList>();

    static ObservableCollection<SampleEntityList> ztowListGlobal
                                    = new ObservableCollection<SampleEntityList>();

    public static ObservableCollection<SampleEntityList> CurrentListOfInventories
    {
        get { return zoneListGlobal; }
        set { zoneListGlobal = value; }
    }

    public static ObservableCollection<SampleEntityList> CurrentSelectedInventories
    {
        get { return ztowListGlobal; }
        set { ztowListGlobal = value; }
    }

}

      

+2


source


You can create your static class with 2 static methods that return your desired object like this example:



public static class GlobalTempStorageVariable
{

    ObservableCollection<SampleEntityList> zoneListGlobal
                                    = new ObservableCollection<SampleEntityList>();
    ObservableCollection<SampleEntityList> ztowListGlobal
                                    = new ObservableCollection<SampleEntityList>();


    public static ObservableCollection<SampleEntityList> GetCurrentListOfInventories()
    {
        return zoneListGlobal;
    }

    public static ObservableCollection<SampleEntityList> GetCurrentSelectedInventories()
    {
        return ztowListGlobal;
    }

}

      

0


source







All Articles