Tech Junkie Blog - Real World Tutorials, Happy Coding!: C#: System.Collections.Generic.Dictionary

Sunday, June 19, 2016

C#: System.Collections.Generic.Dictionary

Namespace:

System.Collections.Generic

Declaration:

Dictionary<string, string> account = new Dictionary<string, string>();

Adding Items:


account.Add("id","1");
account.Add("username", "jackd");

Use in ArrayList: Namespace:



System.Collections

Add Dictionary to ArrayList:


Dictionary<string, string> account = new Dictionary<string, string>();

ArrayList aList = new ArrayList();

account.Add("id","1");
account.Add("username", "jackd");

aList.Add(account);

account = new Dictionary<string, string>();

account.Add("id","2");
account.Add("username", "janed");

aList.Add(account);

account = new Dictionary<string, string>();

account.Add("id","3");
account.Add("username", "d");


Loop Through ArrayList of Dictionary Type:


foreach (Dictionary<string, string> dic in aList)
{
    Response.Write("id: " + dic["id"] + " username: " + dic["username"] + "<br>");
}

1 comment:


  1. Thanks for sharing this.,
    Leanpitch provides crash course in Brain hacks using NLP everyone can use it wisely.

    Brain hacks with NLP

    NLP training

    ReplyDelete

Search This Blog