Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,122 questions

40,782 answers

573 users

How to use name value collection (NameValueCollection ) in C#

2 Answers

0 votes
using System;
using System.Collections.Specialized;
   
class Program
{
    static void Main() {
        NameValueCollection nvc = new NameValueCollection();
          
        nvc.Add("c#", "2");
        nvc.Add("c", "1");
        nvc.Add("php", "5");
        nvc.Add("java", "4");
        nvc.Add("python", "3");
         
        foreach (string key in nvc) {
            Console.WriteLine(nvc[key]);
        }
    }
}
  
   
   
/*
run:
   
2
1
5
4
3
   
*/

 





answered Sep 12, 2019 by avibootz
edited Sep 12, 2019 by avibootz
0 votes
using System;
using System.Linq;
using System.Collections.Specialized;
   
class Program
{
    static void Main() {
        NameValueCollection nvc = new NameValueCollection();
          
        nvc.Add("c#", "2");
        nvc.Add("c", "1");
        nvc.Add("php", "5");
        nvc.Add("java", "4");
        nvc.Add("python", "3");
         
        var items = nvc.AllKeys.SelectMany(nvc.GetValues, (k, v) => new {key = k, value = v});
        
        foreach (var item in items)
            Console.WriteLine(item.key + " - " + item.value);
    }
}
  
   
   
/*
run:
   
c# - 2
c - 1
php - 5
java - 4
python - 3
   
*/

 





answered Sep 12, 2019 by avibootz

Related questions

1 answer 90 views
1 answer 10 views
10 views asked Mar 26 by avibootz
1 answer 32 views
...