![](/img/trans.png)
[英]how to add onclick javascript for Dictionary<string, string>?
[英]How to add data in dictionary <dictionary<string,string>,string>
IDK也無法在Internet上找到有關如何在內部字典中添加數據的解決方案。 如果我嘗試dic1.Add(“”,“”,“”); 其無效。 截至首兩個字符串均未采用字典格式。
您可能需要執行以下操作:
Dictionary<Dictionary<string, string>, string> a = new Dictionary<Dictionary<string, string>, string>();
a.Add(new Dictionary<string, string>() { { "", "" } }, "");
但是在您這樣做之前,我會問自己為什么要嘗試這樣做。 請記住,字典的KEYS是第一個參數,而值是第二個。 您可能不想使用字典作為鍵。
正如其他人所說,這不是正確的方法。
我建議用信息創建一個類
Public Class Thing {
public string prop1 {get; set;}
public string prop2 {get; set;}
public string prop3 {get; set;}
public Thing(string 1, string 2, string 3) {
prop1 = 1;
prop2 = 2;
prop3 = 3;
}
}
然后創建一個類列表。
List<Thing> Things = New List<Thing>();
Things.Add (new Thing("one", "two", "three"));
然后,如果您想搜索一些東西:
Thing foundThing = Things.Where(x => x.prop1 == "Whatever you want to search for").FirstOrDefault();
或新的事物列表:
List<Thing> FilteredListOfThings = Things.Where(x => x.prop1 == "Whatever you want to search for");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.