检查重点在NameValueCollection中存在 [英] Check if Key Exists in NameValueCollection
问题描述
是否有一个快速和简单的方法来检查,如果一个关键的NameValueCollection中不存在通过它循环?
寻找()类似Dictionary.ContainsKey或相似
有许多方法来解决这当然。只是想知道,如果有人可以帮我挠脑痒痒的。
从的 MSDN :
本属性返回null在下列情况下:
1)如果指定键没有找到;
块引用>
所以你正好可以:
NameValueCollection中收集= ...
字符串值=收集[关键]
如果(价值== NULL)//键不存在,
2)如果指定键被发现,其相关值为空。
块引用>
收集[关键]
通话base.Get()
然后base.FindEntry( )
内部使用的Hashtable
与性能O(1)。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 similar.
There are many ways to solve this of course. Just wondering if someone can help scratch my brain itch.
解决方案From MSDN:
This property returns null in the following cases:
1) if the specified key is not found;
So you can just:
NameValueCollection collection = ... string value = collection[key]; if (value == null) // key doesn't exist
2) if the specified key is found and its associated value is null.
collection[key]
callsbase.Get()
thenbase.FindEntry()
which internally usesHashtable
with performance O(1).这篇关于检查重点在NameValueCollection中存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!