2016-09-29 6 views
0

私は私の自己定義された設定タグのアプリの設定をロードしようとするが、私は次のエラーを得た:読書KeyValueConfigurationElement

Error 62 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Configuration.KeyValueConfigurationElement[]'. An explicit conversion exists (are you missing a cast?)

あなたはこれを解決する方法任意のアイデアを持っていますか?私が持っているコードは次の通りです:

KeyValueConfigurationElement[] test = (from KeyValueConfigurationElement e in ((AppSettingsSection)ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).GetSection("mySection")).Settings 
                     where e.Value == "1" 
                     select e); 

「どこで」コードで強調表示されています。私はこれがかなりシンプルだと思うが、私はそれを解決することはできない。

答えて

3

あなたは、式の最後に.ToArray()を置く必要があります:

KeyValueConfigurationElement[] test = (from KeyValueConfigurationElement e in ((AppSettingsSection)ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).GetSection("mySection")).Settings 
     where e.Value == "1" 
     select e).ToArray(); 
+0

うん、TKSを!!それはエラーを解決しました! – Trowa