【问题标题】:C# create Dictionary of int and arraysC# 创建整数和数组字典
【发布时间】:2019-03-12 16:14:13
【问题描述】:

如何创建包含整数作为键和数组作为值的字典。这是我在 dotnetfiddle.net 上尝试过的,但没有成功:

Dictionary<int, double[]> dict;
double[] prices = new double[20];
dict = new Dictionary<int, prices>();

Dictionary<int, double[]> dict;
dict = new Dictionary<int, new double[20]>();

Dictionary<int, double[]> dict;
dict = new Dictionary<int, double[20]>();

【问题讨论】:

  • Dictionary&lt;int, double[]&gt; dict = new Dictionary&lt;int, double[]&gt;(); ?

标签: c# .net dictionary


【解决方案1】:

你可以试试这个。

Dictionary&lt;TKey,TValue&gt; 是泛型类型,您只能在其上设置合约类型。

我认为您正在寻找 Add 方法来添加 double 数组。

Dictionary<int, double[]>  dict = new Dictionary<int, double[]>();
dict.Add(1,new double[20]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    • 2013-11-28
    相关资源
    最近更新 更多