How to compare multidimensional arrays in C# ?

前端 未结 4 899
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 23:47

How to compare multidimensional arrays? Just true/false.

double[,] data1 = new double[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };    
double[,] data2 = ne         


        
4条回答
  •  借酒劲吻你
    2020-12-31 00:20

    You can flat a multi-dimension array with .Cast

    Console.WriteLine("2D Array");
    String[,] array2d = new String[,] { { "A1", "B1" }, { "A2", "B2" } };
    foreach(var s in array2d.Cast())
        Console.Write(s + ", ");
    
    Console.WriteLine("\r\n3D Array");
    String[,] array3d = new String[,] { { "A1", "B1", "C1" }, { "A2", "B2", "C1" } };
    foreach (var s in array3d.Cast())
        Console.Write(s + ", ");
    

    Output

    2D Array
    A1, B1, A2, B2, 
    3D Array
    A1, B1, C1, A2, B2, C1, 
    

提交回复
热议问题