Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何向数组中添加元素_C#_Arrays_Json - Fatal编程技术网

C# 如何向数组中添加元素

C# 如何向数组中添加元素,c#,arrays,json,C#,Arrays,Json,我有这些阵列 int[] ivrArray = { 1, 0, 0, 0}; int[] agentsArray = { 0, 2, 0, 0 }; int[] abandonedArray = { 0, 0, 3, 0}; int[] canceledArray = { 0, 0, 0, 4}; 我用了这本字典: Dictionary<string, int[][]> dictionary = new Dictionary<string, int[][]>

我有这些阵列

int[] ivrArray = { 1, 0, 0, 0};
int[] agentsArray = { 0, 2, 0, 0 };
int[] abandonedArray = { 0, 0, 3, 0};
int[] canceledArray = { 0, 0, 0, 4};
我用了这本字典:

 Dictionary<string, int[][]> dictionary = new Dictionary<string, int[][]>
            {
                {"IVR", ivrArray.Select(_ => new[] {_}).ToArray()},
                {"Agents", agentsArray.Select(_ => new[] {_}).ToArray()},
                {"Abandoned", abandonedArray.Select(_ => new[] {_}).ToArray()},
                { "Cancelled",canceledArray.Select(_ => new[] {_}).ToArray()}
            };
可以看到JSON中的每个元素都是这样的数组
[[0]、[0]、[0]、[4]]

我需要向该数组中的每个元素添加另一个值,因此结果如下:

[[1325376000000,0],[1328054400000,0],[1330560000000,0],[1333238400000,0]]
我该怎么做

对于所有四个阵列,这些值都是静态的。

如下操作:

dictionary.Add("new values", new[] 
                             { 
                               new[] {123, 0}, 
                               new[] {123, 0}, 
                               new[] {123, 0}, 
                               new[] {123, 0}
                              });

JSON序列化程序将
List
序列化为JSON数组,因此使用列表将优于数组数组

您的字典应该是
字典
,您可以获得子列表并添加项目:

dict["some"][0].Add(0);

创建数组时只需添加另一个值:
new[]{otherValue,}

您不是在两小时前问过同样的问题吗?除此之外,您真的觉得应该创建一个新类型,其中包含IVR、代理、废弃等的属性。然后您可以只有一个集合。在创建数组时只需添加其他值:new[]{otherValue,}@SonerGönül不那是完全不同的question@sjkm你能给我一个答案吗?所以我需要为四个元素做这个,它们是
ivr
代理
放弃
取消
,没有通用的方法吗?就像我在问题中给出的一样
dict["some"][0].Add(0);