Skip to content

Jagged array in C#

anji varikuti

Asked Dec 13, 2011, 8:31 PM EST2 answers
Share
LinkedInX
Hai sir

        I want know for loop explanation in jagged array...in this loop i want "(j == (intJaggedArray[i].Length - 1) ? "" : "")" meaning & usage of this....Plz tell me !


for (int i = 0; i < intJaggedArray.Length; i++)
           {
               System.Console.Write("element({0}):", i);
               for (int j = 0; j < intJaggedArray[i].Length; j++)
               {
                   System.Console.Write("{0}{1}", intJaggedArray[i][j], j == (intJaggedArray[i].Length - 1) ? "" : "");
               }
               System.Console.WriteLine();

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    hey anji,
    jagged array is actually array of array in which number of column for each row is different

    so here from
    for (int j = 0; j < intJaggedArray[i].Length; j++)
                   {
                       System.Console.Write("{0}{1}", intJaggedArray[i][j], j == (intJaggedArray[i].Length - 1) ? "" : "");
                   }

    intJaggedArray[i].Length we can know the column/length of i th row 
    and it is iteration through column of i th row so from "j == (intJaggedArray[i].Length - 1) ? "" : "")" we can come to know that is j at the last position/column of the i th row or not
    0
  • 1 short reply
    • 0
      Thank you so much sir....
      0