Wednesday 17 September 2014

Dictionary(Generics) in c# asp.net | example and output

In this article i am going to show how to use generics using dictionary .
basically dictionary uses key value pair to display record.
we can add , remove , insert data in dictionary using key / value pair .
but this is that you need to  follow some rules.


To declare or define dictionary is

Dictionary <string , Int32> myFirstdictionary=new Dictionary<string,int>();


here my dictionary name is myFirstdictionary.
where i m pasing key as string and value will be int32,
now to add value in data using key we use key and pair value.
like this...

myFirstdictionary.Add("dev", 1);

where "dev" is string
and 1 is value type of  int.


Now to fetch data fromdictionary row by row we need to use for or foreach loop.


foreach(KeyValuePair<string, Int32> keys in myFirstdictionary)
        {
            Response.Write(keys.Key +"/"+ keys.Value + "<br/>");

        }



it will print data like this as printed below.





Share This
Latest
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: