How to use Dictionary Class in C# using Asp.Net

Dictionary Class in C#

C# Dictionary class  represent the key and pair values . set of pair values like key is a course means amount is a pair values.

This class is defined in the System.Collections.Generic namespace.


 Dictionary<stringint>;



Display Dictionary key and value   <string,int> using KeyValuePair



Code

 Dictionary<stringint> value = new Dictionary<stringint>();
        value.Add("Asp.Net",5999);
        value.Add("C#", 7999);
        value.Add("Jquery", 8999);
        value.Add("JavaScript", 7666);
        value.Add("VB.NET", 6999);
        foreach(KeyValuePair<string,int> val in value)
        {
            Response.Write(string.Format("{0},{1}",val.Key,val.Value)+"<br>");
   }





Code



Display Dictionary Key only   <string,int> using KeyValuePair

Dictionary<stringint> value = new Dictionary<stringint>();


        value.Add("Asp.Net",5999);

        value.Add("C#", 7999);

        value.Add("Jquery", 8999);
        value.Add("JavaScript", 7666);
        value.Add("VB.NET", 6999);
        foreach(KeyValuePair<string,int> val in value)
        {
            Response.Write(string.Format("{0}",val.Key+"<br>"));

        }




Code


Display Dictionary value   <string,int> using KeyValuePair

Dictionary<stringint> value = new Dictionary<stringint>();
        value.Add("Asp.Net",5999);
        value.Add("C#", 7999);
        value.Add("Jquery", 8999);
        value.Add("JavaScript", 7666);
        value.Add("VB.NET", 6999);
        foreach(KeyValuePair<string,int> val in value)
        {
            Response.Write(string.Format("{0}",val.Value+"<br>"));


        }






Code



Display Dictionary key  Contains key check from dictionary  1000 is check result is NO



Dictionary<stringint> value = new Dictionary<stringint>();
        value.Add("Asp.Net",5999);
        value.Add("C#", 7999);
        value.Add("Jquery", 8999);
        value.Add("JavaScript", 7666);
        value.Add("VB.NET", 6999);
        if (value.ContainsKey("1000") == true)
        {
            Response.Write("YES");

        }
        else
        {
            Response.Write("NO");

        }















0 comments:

Post a Comment