Finding array dimensions

This is a discussion on Finding array dimensions within the C# Programming forums, part of the General Programming Boards category; How can i determine the dimensions of a multi dimensional array. for example. if i create a 2 dimensional array ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    85

    Finding array dimensions

    How can i determine the dimensions of a multi dimensional array.

    for example.
    if i create a 2 dimensional array ( int [,] ) and read in some information (which will be variable in length)
    can i i find the values for [x,y] of this array ?

    i do not need the length, as this return all elements rather than the elements of each dimension.

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    There is no way to do this in C# that I've ever seen. But why does it matter?

    If this array will vary in size from invocation, then when invoking your class (or wherever you invoke the array), save the params that were used for creating the size of the array. If your array is just constant then you can make some constants to define the size.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    85
    just did a quick search for something on this and came up with an artical which explains how to use Arraylists to create arrays where you cannot predetermine the length of the array.

    http://authors.aspalliance.com/remas...DynamicArrays/

    this is only for a single dimension array but im sure you can see the need to be able to check this information once you have read in the data.

    this may be useful to someone out there and save them a search

  4. #4
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Sure, but arraylists aren't true arrays, and they aren't multidimensional. Perhaps you can make a list of structs to do what you need. Or if you really want a 2d array "type" that can expand and shrink, perhaps make a list of lists. This would allow you to iterate through each sub list on the list and add up the length.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Set an array with unknown dimensions as global
    By paok in forum C Programming
    Replies: 11
    Last Post: 12-07-2007, 01:37 PM
  2. Replies: 8
    Last Post: 01-23-2007, 02:31 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. Array with user-defined dimensions
    By Jasel in forum C++ Programming
    Replies: 2
    Last Post: 11-02-2003, 09:58 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21