Windows应用商店 - ApplicationDataCompositeValue Int32值为null

时间:2015-01-17 05:11:33

标签: c# windows-store-apps

在下面的代码中,我可以使用:

访问int值1
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
        }

1 个答案:

答案 0 :(得分:0)

除非你在写这个问题时写错字,否则我会认为原因是intVal的大写。

您将其存储为intval(小写v):

composite["intval"] = 1;

您正在阅读它intVal(大写V):

object intVal = composite["intVal"];

值名称区分大小写。