7
ฉันสามารถใช้ตัวเริ่มต้นการรวบรวมสำหรับรายการพจนานุกรม <TKey, TValue> ได้หรือไม่
ฉันต้องการใช้ตัวเริ่มต้นการรวบรวมสำหรับรหัสบิตถัดไป: public Dictionary<int, string> GetNames() { Dictionary<int, string> names = new Dictionary<int, string>(); names.Add(1, "Adam"); names.Add(2, "Bart"); names.Add(3, "Charlie"); return names; } โดยทั่วไปแล้วควรเป็นดังนี้: return new Dictionary<int, string> { 1, "Adam", 2, "Bart" ... แต่ไวยากรณ์ที่ถูกต้องสำหรับสิ่งนี้คืออะไร?