C#具有参数数组的集合初始化器
示例
您可以混合使用普通参数和参数数组:
public class LotteryTicket : IEnumerable{ public int[] LuckyNumbers; public string UserName; public void Add(string userName, params int[] luckyNumbers){ UserName = userName; Lottery = luckyNumbers; } }
现在可以使用以下语法:
var Tickets = new List<LotteryTicket>{ {"Mr Cool" , 35663, 35732, 12312, 75685}, {"Bruce" , 26874, 66677, 24546, 36483, 46768, 24632, 24527}, {"John Cena", 25446, 83356, 65536, 23783, 24567, 89337} }