【问题标题】:I want to get the "Index array" from a multi-dimensional array我想从多维数组中获取“索引数组”
【发布时间】:2018-10-23 17:45:39
【问题描述】:

我创建一个多维数组如下:

    List<int> indexList = GetFromSomewher()
    Results = Array.CreateInstance(typeof(System.Double),indexList.ToArray() );

    foreach (DataRow row in table.Rows)
    {
        List<int> indexInstance = new List<int>();
        for (int d = 0; d < DegreesOfFreedom; d++)
        {
            indexInstance.Add(DimDict[d][row.Field<double>(d)]);
        }
        Results.SetValue(row.Field<double>(DegreesOfFreedom), indexInstance.ToArray());
    }

然后,一旦创建,我想查看索引数组和值。但这只会给我“价值”。我可以在调试中看到索引数组 - 但无法访问它。

    foreach (var res in Results)
    {
        Console.WriteLine("");
    }

【问题讨论】:

    标签: c# arrays multidimensional-array


    【解决方案1】:

    听起来像是一个不起眼的 for 循环的工作!

        static void Main(string[] args)
        {
            int[][] test = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } };
    
             for(int i = 0; i < test.Length; i++)
            {
                for (int j = 0; j < test[i].Length; j++)
                {
                    Console.WriteLine($"Index: [{i},{j}]: {test[i][j]}");
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2018-03-28
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 2014-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多