Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在c#4.5中存储临时列表值?_C#_Asp.net_Wpf_List - Fatal编程技术网

有没有办法在c#4.5中存储临时列表值?

有没有办法在c#4.5中存储临时列表值?,c#,asp.net,wpf,list,C#,Asp.net,Wpf,List,我需要临时存储列表值,并且需要在另一个c#类中访问该列表值。该过程类似于Asp.net中的会话。任何人请分享一些关于这个想法的想法 这是我的密码: static class GlobalTempStorageVariable { ObservableCollection<SampleEntityList> zoneListGlobal = new ObservableCollection<Samp

我需要临时存储列表值,并且需要在另一个c#类中访问该列表值。该过程类似于Asp.net中的会话。任何人请分享一些关于这个想法的想法

这是我的密码:

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; }
    }

  }
class1.cs:

    ObservableCollection<SampleEntityList> zoneList = new ObservableCollection<SampleEntityList>();
    ObservableCollection<SampleEntityList> ztowList = new ObservableCollection<SampleEntityList>();
   GlobalTempStorageVariable. ???(its not showing the property)..

如果您有任何帮助,我们将不胜感激。

您可以使用2个返回所需对象的静态方法构建您的静态类,例如:

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;
    }

}
公共静态类GlobalTempStorageVariable
{
可观测采集区域列表全局
=新的ObservableCollection();
可观测收集ztowListGlobal
=新的ObservableCollection();
公共静态ObservableCollection GetCurrentListOfInventories()
{
返回区域列表全局;
}
公共静态ObservableCollection GetCurrentSelectedInventories()
{
返回ztowListGlobal;
}
}

静态属性不能访问非静态字段,zoneListGlobal和ZtoListGlobal也应该是静态的,以便其属性可以访问:

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; }
    }

}
静态类GlobalTempStorageVariable
{
静态可观测采集区域列表全局
=新的ObservableCollection();
静态可观测采集ztowListGlobal
=新的ObservableCollection();
公共静态可观测集合当前存货清单
{
获取{return zoneListGlobal;}
设置{zoneListGlobal=value;}
}
公共静态可观测集合CurrentSelectedInventory
{
获取{return ztowListGlobal;}
设置{ztowListGlobal=value;}
}
}

这是一种糟糕的做法。阅读,但可以将其存储在静态类或属性中。在class1中公开zoneList静态,然后像在class2中访问class1.zoneList一样访问它,而不在class2中创建class1实例。您能再次阅读我编辑的帖子吗?@RajDeInno不使用属性,而是使用返回对象的静态方法。请看我的答案如何执行它。