我有课:
public class Item
{
public List<int> val { get; set; }
public string info { get; set; }
}
public class IndexedDictionary : KeyedCollection<List<int>, Item>
{
protected override List<int> GetKeyForItem(Item item)
{
return item.val;
}
}
在'main()'方法中:
IndexedDictionary dic = new IndexedDictionary();
dic.Add(new Item() { val = new List<int>() { 1, 2, 3 }, info = "Hello" });
dic.Add(new Item() { val = new List<int>() { 1 }, info = "Bla.." });
Console.WriteLine(dic[0].info);
Console.WriteLine(dic[new List<int>() { 1 }].info);
Console.ReadLine();
我收到错误:
Console.WriteLine(dic[new List<int>() { 1 }].info);
你能纠正我的代码吗?全部