Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multidimenitonal Arrays

Multidimenitonal Arrays

Scheduled Pinned Locked Moved C#
helpalgorithmsdata-structuresquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eric eD
    wrote on last edited by
    #1

    I just got into school for Computer Information Systems, and I am currently in my first programming class (ROOKIE!!!) I got bored with the assignments they were giving me so I decided to start my own project. However I am running into a problem. I created a StreamReader() in order to read a .txt file and distribute the contents into a [250,4] array. Now I've got all of that working, but the array is not completely filled. There is more to be added during the execution of the program. Now to the point. I am needing to search the first column of the array for a spacific value, and have it return the subscript so that I can access the value of the 4th column at that subscript. Now the only method that I have been shown for this is BinarySearch(); but for this to work the array must be in ascending order. Come to find out the Array.Sort() method only works on one-dimentional arrays... So how would I accomplish sorting the multidimentional array so that I keep all of the information in it's appropriate 'row'? Or if I can't sort it, is there another method that might serve the same purpose? Any help would be greatly appreciated! (Please keep it reletively simple, I'm still gettin' familiar with the terminology) Eric

    G 1 Reply Last reply
    0
    • E Eric eD

      I just got into school for Computer Information Systems, and I am currently in my first programming class (ROOKIE!!!) I got bored with the assignments they were giving me so I decided to start my own project. However I am running into a problem. I created a StreamReader() in order to read a .txt file and distribute the contents into a [250,4] array. Now I've got all of that working, but the array is not completely filled. There is more to be added during the execution of the program. Now to the point. I am needing to search the first column of the array for a spacific value, and have it return the subscript so that I can access the value of the 4th column at that subscript. Now the only method that I have been shown for this is BinarySearch(); but for this to work the array must be in ascending order. Come to find out the Array.Sort() method only works on one-dimentional arrays... So how would I accomplish sorting the multidimentional array so that I keep all of the information in it's appropriate 'row'? Or if I can't sort it, is there another method that might serve the same purpose? Any help would be greatly appreciated! (Please keep it reletively simple, I'm still gettin' familiar with the terminology) Eric

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Eric (eD) wrote:

      Now the only method that I have been shown for this is BinarySearch(); but for this to work the array must be in ascending order.

      You don't need to use a method for searching. Just loop throught the items and look for the value. If the rows in the array have different meaning, perhaps you shouldn't use an array at all, but an object oriented solution like a list of objects. If you want to locate the items by a specific value, you can use a dictionary of objects. Example: // create a dictionary Dictionary<int, Person> persons = new Dictionary<int, Person>; // add persons to the dictionary persons.Add(7, new Person("Paul", "Simon")); persons.Add(42, new Person("Art", "Garfunkel")); // find a person by key Person art = persons[42];

      --- single minded; short sighted; long gone;

      J E 2 Replies Last reply
      0
      • G Guffa

        Eric (eD) wrote:

        Now the only method that I have been shown for this is BinarySearch(); but for this to work the array must be in ascending order.

        You don't need to use a method for searching. Just loop throught the items and look for the value. If the rows in the array have different meaning, perhaps you shouldn't use an array at all, but an object oriented solution like a list of objects. If you want to locate the items by a specific value, you can use a dictionary of objects. Example: // create a dictionary Dictionary<int, Person> persons = new Dictionary<int, Person>; // add persons to the dictionary persons.Add(7, new Person("Paul", "Simon")); persons.Add(42, new Person("Art", "Garfunkel")); // find a person by key Person art = persons[42];

        --- single minded; short sighted; long gone;

        J Offline
        J Offline
        joon vh
        wrote on last edited by
        #3

        Didn't know that was possible with dictionaries, that's cool! I would probably create a custom class (like you did with Person) and use ArrayList or something similar. I would only use old-school multi-dim arrays if performance was a real issue. But with 250x4 I don't think it can be ;) g'luck


        Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

        1 Reply Last reply
        0
        • G Guffa

          Eric (eD) wrote:

          Now the only method that I have been shown for this is BinarySearch(); but for this to work the array must be in ascending order.

          You don't need to use a method for searching. Just loop throught the items and look for the value. If the rows in the array have different meaning, perhaps you shouldn't use an array at all, but an object oriented solution like a list of objects. If you want to locate the items by a specific value, you can use a dictionary of objects. Example: // create a dictionary Dictionary<int, Person> persons = new Dictionary<int, Person>; // add persons to the dictionary persons.Add(7, new Person("Paul", "Simon")); persons.Add(42, new Person("Art", "Garfunkel")); // find a person by key Person art = persons[42];

          --- single minded; short sighted; long gone;

          E Offline
          E Offline
          Eric eD
          wrote on last edited by
          #4

          First off, Thanks for your responses! From what I understand, the above looks like it would work. The problem is, I don't know where to start...? (I'm a complete rookie at this) Does anyone know where I can find some sort of instructional for dictionaries? or possibly just a breakdown of the above example? Thanks again.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups