Home >Backend Development >C#.Net Tutorial >How to use NameValueCollection class in C#?

How to use NameValueCollection class in C#?

WBOY
WBOYforward
2023-09-18 08:33:071507browse

如何在 C# 中使用 NameValueCollection 类?

NameValueCollection Sets multiple values ​​for a single key. Now let's see how to use them in a C# program.

Set up the collection -

static NameValueCollection GetCollection() {
   NameValueCollection myCollection = new NameValueCollection();
   myCollection.Add("Tim", "One");
   myCollection.Add("John", "Two");
   myCollection.Add("Jamie", "Three");
   return myCollection;
}

Now use the GetCollection() method and use the "AllKeys" method attribute to display all keys -

NameValueCollection myCollection = GetCollection();
foreach (string key in myCollection.AllKeys) {
   Console.WriteLine(key);
}

The above is the detailed content of How to use NameValueCollection class in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete