asp.net 键值对取值

 
//声明键值对
public static Dictionary<string, string> ball = new Dictionary<string, string> { 
                                               { "2", "篮球" },
                                               { "1", "羽毛球" },
                                               { "19", "桌球" },
                                               { "57", "高尔夫" },
                                               { "165", "足球" },
                                               { "22", "游泳" }};


        string key = context.Request.QueryString["q"].Trim(); 
        StringBuilder items = new StringBuilder();

        //键值对取值
        foreach(var k in ball.Keys)
        {
            if(ball[k].Contains(key))
            {
                items.Append("[" + k+ "]" +ball[k]).Append("\n");

            }     
        }
       
        context.Response.Write(items.ToString()); 


 

你可能感兴趣的:(String,asp.net)