检查重点在NameValueCollection中存在 [英] Check if Key Exists in NameValueCollection

查看:125
本文介绍了检查重点在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] calls base.Get() then base.FindEntry() which internally uses Hashtable with performance O(1).

这篇关于检查重点在NameValueCollection中存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆