Dictionary:
Dictionary in C# is same as English dictionary. English dictionary is a collection of words and their definitions, often listed alphabetically in one or more specific languages. In the same way, the Dictionary in C# is a collection of Keys and Values, where key is like word and value is like definition.
Dictionary in C# is same as English dictionary. English dictionary is a collection of words and their definitions, often listed alphabetically in one or more specific languages. In the same way, the Dictionary in C# is a collection of Keys and Values, where key is like word and value is like definition.
Dictionary<TKey, TValue> is a generic collection included in the System.Collection.Generics namespace. TKey denotes the type of key and TValue is the type of TValue.
Code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace dictionaryDemo
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, object> dt = new Dictionary<string, object>();
- dt.Add("Roll",1001);
- dt.Add("Name","Sujan Hasan");
- dt.Add("Dept","CSE");
- dt.Add("Email","sujanhasan@gmail.com");
- dt.Add("Age",21);
- print(dt);
- Console.ReadKey();
- }
- public static void print(Dictionary<string, object> dictionary)
- {
- foreach (string x in dictionary.Keys)
- {
- Console.WriteLine(x+" : "+dictionary[x]);
- }
- }
- }
- }
0 Comments:
Post a Comment