如何在不知道值的情况下实例化具有特定数量值的列表?

How to instantiate a list with a specific numbers of values without know the value?

我正在使用 wpf 的 LiveChart,我想用 30 个值实例化一个 Decimal 的列表(就像 space 作为数组一样),实际上我做了:

public SeriesCollection MonthProfit {get;set;} = new SeriesCollection();

 int i = 0;
 MonthProfit[0].Values = new ChartValues<decimal>();
 MonthProfit[0].Values[i] = 25;

但我得到:

Index out of range

如何在索引中定义 30 个值 0

在我看来,您可以使用接受 IEnumerable<T>:

ChartValues 构造函数
MonthProfit[0].Values = new ChartValues<decimal>(Enumerable.Repeat(0m, 30));