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. working with 2D Array

working with 2D Array

Scheduled Pinned Locked Moved C#
data-structureshelptutorial
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.
  • S Offline
    S Offline
    signimage
    wrote on last edited by
    #1

    int[] W=new int[10]; int[][] wind=new int[2][]; Color c1 = h.GetPixel(1,1); W[0]=c1.ToArgb(); wind[0][0]=W[0]; this code give me run time error at wind[0][0]=W[0]; I do not know why,is there any error,can some one guide me,

    M J 2 Replies Last reply
    0
    • S signimage

      int[] W=new int[10]; int[][] wind=new int[2][]; Color c1 = h.GetPixel(1,1); W[0]=c1.ToArgb(); wind[0][0]=W[0]; this code give me run time error at wind[0][0]=W[0]; I do not know why,is there any error,can some one guide me,

      M Offline
      M Offline
      Martin 0
      wrote on last edited by
      #2

      Hello, Yes you have a null ref. exception here. wind[0] and wind[1] are not initialized //Constructor code for(int x=0;x

      1 Reply Last reply
      0
      • S signimage

        int[] W=new int[10]; int[][] wind=new int[2][]; Color c1 = h.GetPixel(1,1); W[0]=c1.ToArgb(); wind[0][0]=W[0]; this code give me run time error at wind[0][0]=W[0]; I do not know why,is there any error,can some one guide me,

        J Offline
        J Offline
        jjansen
        wrote on last edited by
        #3

        You forgot to allocate the size of the second dimension of variable wind. You need to do something like this: int[][] wind = new int[2][]; wind[0] = new int[3]; wind[1] = new int[5]; Set the size of the first dimension to 2 (you've done that). Then you need to set the sizes of the second dimension for each of the elements (!) in the first dimension. By the way, if you want the sizes of the second dimension to be the same, you might consider using a two-dimensional array like this: int[,] wind = new int[2, 3];

        M 1 Reply Last reply
        0
        • J jjansen

          You forgot to allocate the size of the second dimension of variable wind. You need to do something like this: int[][] wind = new int[2][]; wind[0] = new int[3]; wind[1] = new int[5]; Set the size of the first dimension to 2 (you've done that). Then you need to set the sizes of the second dimension for each of the elements (!) in the first dimension. By the way, if you want the sizes of the second dimension to be the same, you might consider using a two-dimensional array like this: int[,] wind = new int[2, 3];

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Hello,

          jjansen wrote:

          By the way, if you want the sizes of the second dimension to be the same, you might consider using a two-dimensional array like this: int[,] wind = new int[2, 3];

          Thank you for the information about the 2D-array. (never used it before) How do I get access to a spezial array? (int[] intarray = wind[0]) //doesn't work Thanks for your time Martin

          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