Multiple values for a single config key

后端 未结 10 2032
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 01:37

I\'m trying to use ConfigurationManager.AppSettings.GetValues() to retrieve multiple configuration values for a single key, but I\'m always receiving an array o

10条回答
  •  执笔经年
    2020-12-05 02:17

    I use naming convention of the keys and it works like a charm

    
    
      
        

    var section1 = ConfigurationManager.GetSection("section1") as NameValueCollection;
    for (int i = 0; i < section1.AllKeys.Length; i++)
    {
        //if you define the key is unique then use == operator
        if (section1.AllKeys[i] == "keyName1")
        {
            // process keyName1
        }
    
        // if you define the key as a list, starting with the same name, then use string StartWith function
        if (section1.AllKeys[i].Startwith("keyName2"))
        {
            // AllKeys start with keyName2 will be processed here
        }
    }
    

提交回复
热议问题