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. Simple Q about multidimension array .. plz Help

Simple Q about multidimension array .. plz Help

Scheduled Pinned Locked Moved C#
questiondatabasedata-structureshelp
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.
  • L Offline
    L Offline
    legend_of_zanado
    wrote on last edited by
    #1

    how can i get index of specified item in multidimension array ?

    S 1 Reply Last reply
    0
    • L legend_of_zanado

      how can i get index of specified item in multidimension array ?

      S Offline
      S Offline
      ScottM1
      wrote on last edited by
      #2

      By using nested for loops to step through and checking for when the element is equal to your value.

      valueSearch = "Value to search for";
      for (int x = 0; x < array.GetLength(0); x++)
      {
      for (int y = 0; y < array.GetLength(1); y++)
      {
      for (int z = 0; z < array.GetLength(2); z++)
      {
      if (array[x][y][z] == valueSearch)
      {
      //store values for x, y and z. Those will be your indices
      }
      }
      }
      }

      There are 10 types of people in the world, those who understand binary and those who dont.

      J 1 Reply Last reply
      0
      • S ScottM1

        By using nested for loops to step through and checking for when the element is equal to your value.

        valueSearch = "Value to search for";
        for (int x = 0; x < array.GetLength(0); x++)
        {
        for (int y = 0; y < array.GetLength(1); y++)
        {
        for (int z = 0; z < array.GetLength(2); z++)
        {
        if (array[x][y][z] == valueSearch)
        {
        //store values for x, y and z. Those will be your indices
        }
        }
        }
        }

        There are 10 types of people in the world, those who understand binary and those who dont.

        J Offline
        J Offline
        Justin Jones 0
        wrote on last edited by
        #3

        I would say that if you need to be searching, arrays aren't the way to go. But if you must use arrays, the only tip I would add to the above is a break statement jump out of the nested for loops when you actually find the value (no need in running through the rest of the items).

        J Make the logo bigger

        S 1 Reply Last reply
        0
        • J Justin Jones 0

          I would say that if you need to be searching, arrays aren't the way to go. But if you must use arrays, the only tip I would add to the above is a break statement jump out of the nested for loops when you actually find the value (no need in running through the rest of the items).

          J Make the logo bigger

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          True that

          There are 10 types of people in the world, those who understand binary and those who dont.

          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