ASP.NET 범용 형식 사전 조작

  :http://www.cnblogs.com/ytjjyy/archive/2012/04/17/2453362.html

protected void Page_Load(object sender, EventArgs e)
    {
        //  Dictionary  
        Dictionary<string, string> dit = new Dictionary<string, string>();
        dit.Add("13", "  ");
        dit.Add("22", "  ");
        Response.Write("  " + dit.Count + "<br/>");//        
        dit.Remove("13");//       
        if (!dit.ContainsKey("13"))
        {
            dit.Add("13", "  1");
        }//                
        foreach (KeyValuePair<string, string> kvp in dit)
        {
            Response.Write(kvp.Key);
            Response.Write("=====" + kvp.Value);
            Response.Write("<br/>");
        }//         

        Dictionary<string, string>.KeyCollection ditkey = dit.Keys;
        foreach (string k in ditkey)
        {
            Response.Write(k + "<br/>");
        }//          

        Dictionary<string, string>.ValueCollection ditvalue = dit.Values;
        foreach (var v in ditvalue)
        {
            Response.Write(v + "<br/>");
        }//           

        foreach (var ditk in dit.Keys)
        {
            Response.Write(ditk + "<br/>");
        }//             

        string f = dit["13"];
        Response.Write(f);//         

        string s = string.Empty;
        if (dit.TryGetValue("13", out s))
        {
            Response.Write("<br/>  ");
        }
        else
        {
            Response.Write("<br/>   ");
        }//         

        //  List     
        List<string> a = new List<string>();
        a.Add("aa");
        a.Add("bb");
        foreach (string b in a)
        {
            Response.Write("<br/>" + b + "<br/>");
        }
        //  IList  
        IList<string> Il = new List<string>();
        Il.Add("11");
        Il.Add("22");
        foreach (var i in Il)
        {
            Response.Write(i + "<br/>");
        }
    }

좋은 웹페이지 즐겨찾기