帶引數陣列的集合初始值設定項
你可以混合普通引數和引數陣列:
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}
}