public static Dictionary<string,List<LookupItem>> dict;
if (dict == null)
{
dict = IsolatedStorage.GetDropDowns();
return dict["Priority"]
}
else
return dict["Priority"];
Run Code Online (Sandbox Code Playgroud)
要么
try
{
return dict["Priority"];
}
catch(KeyNotFoundException e)
{
dict = IsolatedStorage.GetDropDowns();
return dict["Priority"];
}
Run Code Online (Sandbox Code Playgroud)
这是一个silverlight应用程序,我有下拉缓存在隔离存储中(如果我必须查询wcf服务的每个查找然后datagrid永远出现,我很清楚,下拉可能会过时,我有一个更新字典的方法当通过回调添加/删除新值时,在我的xaml中,我有一个转换器,它将从dbquery返回的Id转换为相关的LookupItem对象.我知道我永远不应该使用try和catch作为应用程序逻辑的一部分,但我真的需要尽可能快的方法,因此我愿意忽略那个架构禁忌.字典变为空的原因是因为我将字典存储为仲裁类中的静态var,如果用户必须按F5刷新页面,字典将丢失其值,因为重新加载了xap文件和我的缓存页面在登录时执行的将不会执行."优先级"包含一个List.LookupItem包含ComboBoxes所需的键/值等.
1)字典是存储这些信息的最有效方式吗?2)两种方法中的哪一种会产生最快的清单回报?