Two-Dimensional array initializaton

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swetha82
    New Member
    • Jul 2007
    • 7

    #1

    Two-Dimensional array initializaton

    I got a problem in C# with the 2D array initialization. My code is like this....

    Code:
    int[,] x= new int[,]{{1,2,3,4},{5,,6,7,8}};
                MessageBox.Show("total:"+x.Length.ToString());
                MessageBox.Show("rows:"+x.GetLength(0).ToString());
                MessageBox.Show("cols:"+x.GetLength(1).ToString());
    i got so many errors.Is there any problem with this code?
  • programmerboy
    New Member
    • Jul 2007
    • 84

    #2
    Originally posted by swetha82
    I got a problem in C# with the 2D array initialization. My code is like this....

    Code:
    int[,] x= new int[,]{{1,2,3,4},{5,,6,7,8}};
                MessageBox.Show("total:"+x.Length.ToString());
                MessageBox.Show("rows:"+x.GetLength(0).ToString());
                MessageBox.Show("cols:"+x.GetLength(1).ToString());
    i got so many errors.Is there any problem with this code?
    I see that you have two commas after 5. Just delete one and you will be fine.

    Comment

    Working...