还有其他问题,比如KeyValuePair与IDictionary,但我觉得这一个略有不同。
<code>NameValueCollection</code>接受字符串键和字符串值。
KeyValuePair
就像一本字典,你可以告诉它键和值的类型。
我不明白为什么存在NameValueCollection
。用字符串类型初始化KeyValuePair
似乎就足够了。我还注意到NameValueCollection
还有一些方法可供使用,但为什么不将两个类合并为一个呢?
还有其他问题,比如KeyValuePair与IDictionary,但我觉得这一个略有不同。
<code>NameValueCollection</code>接受字符串键和字符串值。
KeyValuePair
就像一本字典,你可以告诉它键和值的类型。
我不明白为什么存在NameValueCollection
。用字符串类型初始化KeyValuePair
似乎就足够了。我还注意到NameValueCollection
还有一些方法可供使用,但为什么不将两个类合并为一个呢?
KeyValuePair
不像字典。它只是一个包含键和值的元组。
NameValueCollection
是相当于的IList<;KeyValuePair<;字符串,IList<;字符串>>>
(请注意,NameValueCollection
早于泛型)-像Get(string)
这样的操作是O(n)
或多个值(这与Dictionary<;string,string>;
不同)。
此类可用于标题、查询字符串和表单数据。
较新的用“替换”数据结构是查找<;字符串,字符串>;
。(但是,它不直接支持与spender注释一样不可变的操作。)
快乐的编码。
NameValueCollection存在于.NET 1.0和1.1中,KeyValuePair是一种泛型类型,直到2.0才添加到.NET中。System.Collections.Specialized所有这些都早于泛型的添加;它包含某些强类型(如果愿意的话,可以专门化),以供用户在不必从对象转换到字符串的情况下使用。
KeyValuePair是用于迭代词典
var dictionary = new Dictionary<int,long>
foreach(var kvp in dictionary)
{
// kvp is KeyValuePair<int,long>. kvp.Key is the int key and kvp.Value is the long value for the key
}
NameValueCollection是可索引的。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...