Raj De Inno Raj De Inno - 18 days ago 7
ASP.NET (C#) Question

Is there any way to store temporary list values in c# 4.5?

I need to store list values impermanent and i need to get to that list values in another c# class. the procedure resemble, Session in Asp.net. Anybody please share a few thoughts regarding this idea.

Here is my code:

class1.cs:

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


I need to store this 2 list values some place locally and i need to get to this two list values to another class.. be that as it may, i would prefer not to go as constructor. I need to store this two rundown values locally..

class2.cs:

??

I have endeavored this code:

Made new static class for setting the Property. What's more, I can't get to the property access outside 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 is not working. Also i am unable to access CurrentListOfInventories & CurrentSelectedInventories outside the class..

class1.cs:

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


Any help would be appreciated..

Answer

A Static property cannot access non-static field, zoneListGlobal and ztowListGlobal should 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; }
    }

}