Home>

You are currently creating a two-dimensional array and want to pass it to a two-dimensional list.
For example, suppose that there is a string type 2D array data in the form of temp [2] [3]. (There is no null data in the contents)
I would like to add this to the declared 2D List ls. Is there any way to declare all the specific row data like Matlab?
I think that it can be done by adding the array data of the i-th row as many as the number of rows as follows.

for (int i = 0;i<2;i ++)
            {
                ls.AddRange (temp [i ,:]);
            }
Supplemental information (FW/tool version etc.)

Visual studio 2017

c#
  • Answer # 1

    Is this the case?

    using System;
    using System.Linq;
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main (string [] args)
            {
                var temp = new string [2] [];
                for (int i = 0;i<temp.Length;i ++)
                {
                    temp [i] = new string [3];
                    for (int j = 0;j<temp [i] .Length;j ++)
                    {
                        temp [i] [j] = $"{i}-{j}";
                    }
                }
                var ls = temp.Select (a =>a.ToList ()). ToList ();
                for (int i = 0;i<ls.Count;i ++)
                {
                    for (int j = 0;j<ls [i] .Count;j ++)
                    {
                        Console.WriteLine ($"i: {i}, j: {j}, content: {ls [i] [j]}");
                    }
                }
                Console.ReadKey ();
            }
        }
    }

  • Answer # 2

    ls.AddRange (temp [i]);

    Is it wrong?