在实例化时分配给字典的最佳方法是什么?
例如,我如何才能myDictionary
低于我myList
所做的一切?
Dictionary<int, string> myDictionary = new Dictionary<int, string>()
{
// this does not work. how to make it work?
(0, "first"),
(1, "second")
};
// here's how it's done with List<T>
List<Int32> myList = new List<int>(){
1,
2,
3
};
答案 0 :(得分:4)
Dictionary<int, string> myDictionary = new Dictionary<int, string>()
{
{0, "first"},
{1, "second"}
};