classNewCollectionInit
{
publicDictionary OldMethod()
{
Dictionary student=newDictionary();
student.Add("张三", 25);
student.Add("李四", 34);
student.Add("王五", 26);
returnstudent;
}
//新的初始化方法
publicDictionary NewMethod()
{
Dictionary student=newDictionary()
{
["张三"] = 25,
["李四"] = 34,
["王五"] = 26
};
returnstudent;
}
}
留言