Check if Key Exists in NameValueCollection

后端 未结 12 753
执念已碎
执念已碎 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:20

    If the collection size is small you could go with the solution provided by rich.okelly. However, a large collection means that the generation of the dictionary may be noticeably slower than just searching the keys collection.

    Also, if your usage scenario is searching for keys in different points in time, where the NameValueCollection may have been modified, generating the dictionary each time may, again, be slower than just searching the keys collection.

提交回复
热议问题