locked
c# arrays RRS feed

  • Question

  • can anyone please tell me what is the use of jagged arrays in real time applications
    Friday, May 24, 2013 7:17 AM

Answers

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

    You can consider jagged array as a movie ticket counter where ticket selling counters are fixed (rows are fixed) but you don't know how many people will be standing in each counter in a queue (column numbers are not fixed can vary on different rows).

    refer Article

    For example:

    int[][] a

    Here a is a jagged array.

    We can say, it is an array of Integer Array.

    a[0]- will point to an Integer Array

    a[1]- will be another Integer Array

    so each of them can have different sized.

    so you can assign 

    var a = new int[2][];
    a[0] = new int[5];
    a[1] = new int[10];

    Here  "a" contains 2 Integer arrays

    First element in "a" contains an Integer Array of 5 elements;

    Second element in "a" contains an Integer Array of 10 elements;

    You can use this when you have a requirement of storing array of data in which each can have different number of data




    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

    Friday, May 24, 2013 11:11 AM
  • Real-world application? I can see a HashTable can be implemented with a jagged array. First dimension is your bucket size, and each bucket has another array which keeps all the elements with the same hash key.

    On C#, most likely you will implement it with an array of List<> but if you just want to duplicate an existing hash table and perform read-only operations, array of arrays with different lengths(jagged array) could be used too.

    apparently someone did this kind of conversion too:

    http://www.codekeep.net/snippets/bd1851d6-c73b-4d5c-abe7-cc4865cc702b.aspx


    www.popekim.com

    Friday, May 24, 2013 6:25 PM

All replies

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

    You can consider jagged array as a movie ticket counter where ticket selling counters are fixed (rows are fixed) but you don't know how many people will be standing in each counter in a queue (column numbers are not fixed can vary on different rows).

    refer Article

    Friday, May 24, 2013 9:31 AM
  • A jagged array is an array whose elements are arrays. The elements of a jagged array can be of different dimensions and sizes. A jagged array is sometimes called an "array of arrays."

    You can consider jagged array as a movie ticket counter where ticket selling counters are fixed (rows are fixed) but you don't know how many people will be standing in each counter in a queue (column numbers are not fixed can vary on different rows).

    refer Article

    For example:

    int[][] a

    Here a is a jagged array.

    We can say, it is an array of Integer Array.

    a[0]- will point to an Integer Array

    a[1]- will be another Integer Array

    so each of them can have different sized.

    so you can assign 

    var a = new int[2][];
    a[0] = new int[5];
    a[1] = new int[10];

    Here  "a" contains 2 Integer arrays

    First element in "a" contains an Integer Array of 5 elements;

    Second element in "a" contains an Integer Array of 10 elements;

    You can use this when you have a requirement of storing array of data in which each can have different number of data




    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

    Friday, May 24, 2013 11:11 AM
  • Real-world application? I can see a HashTable can be implemented with a jagged array. First dimension is your bucket size, and each bucket has another array which keeps all the elements with the same hash key.

    On C#, most likely you will implement it with an array of List<> but if you just want to duplicate an existing hash table and perform read-only operations, array of arrays with different lengths(jagged array) could be used too.

    apparently someone did this kind of conversion too:

    http://www.codekeep.net/snippets/bd1851d6-c73b-4d5c-abe7-cc4865cc702b.aspx


    www.popekim.com

    Friday, May 24, 2013 6:25 PM
  • thanks pope..
    Monday, May 27, 2013 6:12 AM