如何读取redis中的key值中的结果
2个回答
2017-08-28
展开全部
由于数据结构特殊性,NameValueCollection只提供Key的遍历,不提供Value的遍历。必须先知道Key,然后再通过Key取Values。以下是MSDN的示例。usingSystem;usingSystem.Collections;usingSystem.Collections.Specialized;publicclassSamplesNameValueCollection{publicstaticvoidMain(){//CreatesandinitializesanewNameValueCollection.NameValueCollectionmyCol=newNameValueCollection();myCol.Add("red","rojo");myCol.Add("green","verde");myCol.Add("blue","azul");myCol.Add("red","rouge");//DisplaysthevaluesintheNameValueCollectionintwodifferentways.Console.WriteLine("DisplaystheelementsusingtheAllKeyspropertyandtheItem(indexer)property:");PrintKeysAndValues(myCol);Console.WriteLine("DisplaystheelementsusingGetKeyandGet:");PrintKeysAndValues2(myCol);//Getsavalueeitherbyindexorbykey.Console.WriteLine("Index1containsthevalue{0}.",myCol[1]);Console.WriteLine("Key\"red\"hasthevalue{0}.",myCol["red"]);Console.WriteLine();//Copiesthevaluestoastringarrayanddisplaysthestringarray.String[]myStrArr=newString[myCol.Count];myCol.CopyTo(myStrArr,0);Console.WriteLine("Thestringarraycontains:");foreach(StringsinmyStrArr)Console.WriteLine("{0}",s);Console.WriteLine();//Searchesforakeyanddeletesit.myCol.Remove("green");Console.WriteLine("Thecollectioncontainsthefollowingelementsafterremoving\"green\":");PrintKeysAndValues(myCol);//Clearstheentirecollection.myCol.Clear();Console.WriteLine("Thecollectioncontainsthefollowingelementsafteritiscleared:");PrintKeysAndValues(myCol);}publicstaticvoidPrintKeysAndValues(NameValueCollectionmyCol){IEnumeratormyEnumerator=myCol.GetEnumerator();Console.WriteLine("KEYVALUE");foreach(StringsinmyCol.AllKeys)Console.WriteLine("{0,-10}{1}",s,myCol[s]);Console.WriteLine();}publicstaticvoidPrintKeysAndValues2(NameValueCollectionmyCol){Console.WriteLine("[INDEX]KEYVALUE");for(inti=0;i
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询