Check if Key Exists in NameValueCollection

后端 未结 12 750
执念已碎
执念已碎 2020-12-13 16:42

Is there a quick and simple way to check if a key exists in a NameValueCollection without looping through it?

Looking for something like Dictionary.ContainsKey() or

12条回答
  •  没有蜡笔的小新
    2020-12-13 17:05

    I am using this collection, when I worked in small elements collection.

    Where elements lot, I think need use "Dictionary". My code:

    NameValueCollection ProdIdes;
    string prodId = _cfg.ProdIdes[key];
    if (string.IsNullOrEmpty(prodId))
    {
        ......
    }
    

    Or may be use this:

     string prodId = _cfg.ProdIdes[key] !=null ? "found" : "not found";
    

提交回复
热议问题