创建列表时,您可以使用以下起始值加载它:
CounterReclaim.CounterReclaimCards = new List<CounterReclaimCardModels>
{
new CounterReclaimCardModels()
{
CounterReclaimID = 1,
ReclaimType = "Rule22Pool",
ReclaimDisposition = "None"
},
new CounterReclaimCardModels()
{
CounterReclaimID = 2,
ReclaimType = "AwesomeThing",
ReclaimDisposition = "None"
},
variableForAnExistingCounterReclaimCardModels,
//etc...
};
或者,您可以只使用 Add 方法:
CounterReclaim.CounterReclaimCards = new List<CounterReclaimCardModels>();
CounterReclaim.CounterReclaimCards.Add(new CounterReclaimCardModels()
{
CounterReclaimID = 1,
ReclaimType = "Rule22Pool",
ReclaimDisposition = "None"
});
CounterReclaim.CounterReclaimCards.Add(new CounterReclaimCardModels()
{
CounterReclaimID = 2,
ReclaimType = "AwesomeThing",
ReclaimDisposition = "None"
});
CounterReclaim.CounterReclaimCards.Add(variableForAnExistingCounterReclaimCardModels);
此外,您可以使用一些值初始化列表,然后使用 Add 稍后添加更多值。