![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use NameValueCollection class in C#?
The NameValueCollection sets more than one value for a single key. Now let us see how to use them in our C# program.
Set the collection −
static NameValueCollection GetCollection() { NameValueCollection myCollection = new NameValueCollection(); myCollection.Add("Tim", "One"); myCollection.Add("John", "Two"); myCollection.Add("Jamie", "Three"); return myCollection; }
Now with the GetCollection() method use the “AllKeys” method property to display all the keys −
NameValueCollection myCollection = GetCollection(); foreach (string key in myCollection.AllKeys) { Console.WriteLine(key); }
Advertisements