gpt4 book ai didi

c# - 在隔离存储中存储 Dictionary

转载 作者:行者123 更新时间:2023-11-30 17:16:01 24 4
gpt4 key购买 nike

我正在访问服务器并获取一些数据,正在解析这些数据并将其存储在 Dictionary<TKey, TValue> 中.

我存储这个Dictionary<TKey, TValue>隔离存储中的列表。现在,问题是每当我尝试检索 Dictionary<TKey, TValue> (在第二次运行中)我在第一次运行中存储的内容,bean 中每个键的值都将变为空。我不知道存储 Dictionary<TKey, TValue> 的方式是否是错误的。

代码示例:

CacheManager.getInstance().PersistData(CacheManager.SERVICE_TABLE, 
dictionaryList);

public void PersistData(string storageName, object dict)
{
try
{
PersistDataStore.Add(storageName, dict);
PersistDataStore.Save();
}
catch (Exception ex)
{
}
}

最佳答案

我得到了问题的解决方案,字典dict的成员必须被序列化。即,

using System.Runtime.Serialization;
[DataContact]
public class classname()
{
[datamember]
public int propertyname;
}

关于c# - 在隔离存储中存储 Dictionary<TKey, TValue>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7569112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com