如何使用字典的值將其映射到列表。例如,我有Dictionary<int,int> studid= new Dictionary<int,int>();
其中index是關鍵字,id是值。現在我有一個標記列表。字典到清單
如何將id指向標記列表並顯示它們?
如何使用字典的值將其映射到列表。例如,我有Dictionary<int,int> studid= new Dictionary<int,int>();
其中index是關鍵字,id是值。現在我有一個標記列表。字典到清單
如何將id指向標記列表並顯示它們?
您正在使用不正確的數據類型來滿足您的需求。你需要一個字典映射一個關鍵整數列表:
Dictionary<int,List<int>> studid= new Dictionary<int,List<int>>();
你會使用的關鍵,以獲得標記的列表:
var marks = studid[theIndex];
我正在使用標記列表。如何將它映射到字典中:public List
這似乎是她的問題在這裏的延續:http://stackoverflow.com/questions/13691882/adding-items-to-a-list。我仍然不完全確定爲什麼涉及一個Dictionary對象。 – MadHenchbot
使其成爲Dictionary<int, List<int>>
是最簡單的辦法。你的密鑰將是一個int,並且該值可以是一個標記列表。
var dict = new Dictionary<int, List<int>>();
dict.Add(1, new List<int>() { 1, 2, 3, 4 });
您沒有每個鍵的標記列表。每個鍵您都有一個「int」值。 – Oded
有一個'Dictionary>'可以接受嗎? –
你指的是什麼ID? – ryadavilli