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>");
}

No comments:

Post a Comment