Windows 存储 - ApplicationDataCompositeValue Int32 值为空
Windows Store - ApplicationDataCompositeValue Int32 value is null
在下面的代码中,我可以使用以下代码访问 1 的 int 值:
composite.ElementAt(1).Value
然而,当我尝试使用
访问它时
composite["intVal"];
为空
奇怪的是我拥有的另一个字符串值不为空。
为什么当我尝试使用 composite["intVal"];
访问它时它为空?
private void addCompositeValues()
{
ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();
composite["strVal"] = "string";
composite["intval"] = 1;
ApplicationData.Current.RoamingSettings.Values["exampleCompositeSetting"] = composite;
}
private void readCompositeValues()
{
ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)ApplicationData.Current.RoamingSettings.Values["exampleCompositeSetting"];
object strVal = composite["strVal"]; // "string"
object strValKey = composite.ElementAt(0).Key; // "strVal"
object strValValue = composite.ElementAt(0).Value; // "string"
object intVal = composite["intVal"]; // null - why is this null?
object intValKey = composite.ElementAt(1).Key; // "intVal"
object intValValue = composite.ElementAt(1).Value; // 1
}
除非你在写问题时打错了我会假设原因是 intVal
的大小写。
您将其存储为 intval
(小写 v
):
composite["intval"] = 1;
而您读作 intVal
(大写 V
):
object intVal = composite["intVal"];
值名称区分大小写。
在下面的代码中,我可以使用以下代码访问 1 的 int 值:
composite.ElementAt(1).Value
然而,当我尝试使用
访问它时composite["intVal"];
为空
奇怪的是我拥有的另一个字符串值不为空。
为什么当我尝试使用 composite["intVal"];
访问它时它为空?
private void addCompositeValues()
{
ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();
composite["strVal"] = "string";
composite["intval"] = 1;
ApplicationData.Current.RoamingSettings.Values["exampleCompositeSetting"] = composite;
}
private void readCompositeValues()
{
ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)ApplicationData.Current.RoamingSettings.Values["exampleCompositeSetting"];
object strVal = composite["strVal"]; // "string"
object strValKey = composite.ElementAt(0).Key; // "strVal"
object strValValue = composite.ElementAt(0).Value; // "string"
object intVal = composite["intVal"]; // null - why is this null?
object intValKey = composite.ElementAt(1).Key; // "intVal"
object intValValue = composite.ElementAt(1).Value; // 1
}
除非你在写问题时打错了我会假设原因是 intVal
的大小写。
您将其存储为 intval
(小写 v
):
composite["intval"] = 1;
而您读作 intVal
(大写 V
):
object intVal = composite["intVal"];
值名称区分大小写。