Sagar Rawal
Sagar Rawal

Reputation: 1442

What are Jagged Arrays in .NET?

I am learning .NET and i have seen the word "Jagged Arrays". So i want to know that what is the perfect meaning for that.

I am just a beginner in .NET technology so please provide a specific answer for that. If possible please explain with example.

Have a Nice Day

Upvotes: 2

Views: 1026

Answers (5)

S2S2
S2S2

Reputation: 8502

Jagged Array is an "Array of Arrays". More information at MSDN specific to .Net:

http://msdn.microsoft.com/en-us/library/2s05feca.aspx

Upvotes: 2

Manoj Savalia
Manoj Savalia

Reputation: 1402

May be this answer help to you.....

Jagged Array is an array, with each of its element as an array. Each of its element can be of different size or dimension.

Suppose, in below code we are declaring an array having 3 elements, and each of its element is an array itself, and they are of different size..

Eg:

int[][] x = new int[3][];
x[0] = new int[1];
x[1] = new int[10];
x[2] = new int[15];

Upvotes: 5

Jon Skeet
Jon Skeet

Reputation: 1502406

It's an array of arrays, where the sub-arrays may have different sizes. For example:

string[][] jagged = new string[][] {
    new string[] { "one" },
    new string[] { "two", "elements" },
    new string[] { "this", "has", "three" },
};

Compare that with a rectangular array, which doesn't have "sub-arrays" but is just a genuine two-dimensional single array:

string[,] rectangular = new string[,] {
    // These must all have the same length
    { "a", "b" },
    { "c", "d" },
    { "0", "1" }
};

Upvotes: 2

Guffa
Guffa

Reputation: 700592

A jagged array is an array of arrays (specifically a one dimensional array of one dimensional arrays).

The term "jagged" comes from that the inner arrays can be of diffent length, compared to a two dimensional array where the data in each dimension is always the same length.

Upvotes: 1

Pedryk
Pedryk

Reputation: 1663

Have a look at the microsoft msdn library, it has loads of small examples and explains them perfectly.

http://msdn.microsoft.com/en-us/library/2s05feca.aspx

"A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes."

Upvotes: 1

Related Questions