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. Casting multi dimensional arrays

Casting multi dimensional arrays

Scheduled Pinned Locked Moved C#
data-structuresdebugginghelptutorialquestion
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
    Esmo2000
    wrote on last edited by
    #1

    I have an object that I am getting from an Excel cell range. I can look at it in the debugger, its an array of arrays (of objects I think). I want to store this in a variable, but I dont know how to cast it!! I DO know the size of the array of arrays (both, i am completely aware of the dimensions of this object.) Can somebody please help?? So you can see, here is what I have currently but it throws a cast exception: cellR = workS.get_Range("A" + curRow, "F" + curRow); Object theLine = cellR.get_Value(System.Type.Missing); Object[][] theOtherLine = new object[1][]; theOtherLine = (Object[][])theLine; It does so at runtime. Cheers! Jim Did I post well? Rate it! Did I post badly? Rate that too!

    C 1 Reply Last reply
    0
    • E Esmo2000

      I have an object that I am getting from an Excel cell range. I can look at it in the debugger, its an array of arrays (of objects I think). I want to store this in a variable, but I dont know how to cast it!! I DO know the size of the array of arrays (both, i am completely aware of the dimensions of this object.) Can somebody please help?? So you can see, here is what I have currently but it throws a cast exception: cellR = workS.get_Range("A" + curRow, "F" + curRow); Object theLine = cellR.get_Value(System.Type.Missing); Object[][] theOtherLine = new object[1][]; theOtherLine = (Object[][])theLine; It does so at runtime. Cheers! Jim Did I post well? Rate it! Did I post badly? Rate that too!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Object[][] is a jagged array. Perhaps you need Object[,] ?? Christian Graus - Microsoft MVP - C++

      E 1 Reply Last reply
      0
      • C Christian Graus

        Object[][] is a jagged array. Perhaps you need Object[,] ?? Christian Graus - Microsoft MVP - C++

        E Offline
        E Offline
        Esmo2000
        wrote on last edited by
        #3

        Wow, thank you! How is that handled differtly in memory? Why do both of those exist? Cheers, Jim Did I post well? Rate it! Did I post badly? Rate that too!

        S 1 Reply Last reply
        0
        • E Esmo2000

          Wow, thank you! How is that handled differtly in memory? Why do both of those exist? Cheers, Jim Did I post well? Rate it! Did I post badly? Rate that too!

          S Offline
          S Offline
          S Senthil Kumar
          wrote on last edited by
          #4

          Jagged arrays is simply an array of arrays, while a multidimensional array is truly one array with multiple dimensions. Jagged arrays can have different dimensions for each row in the first dimension, for eg, whereas multidimensional arrays always have the same number of dimensions.

          int [][] x = new int[2][];
          x[0] = new int[5]; // First row has 5 columns
          x[1] = new int[10];// Second row has 10
          ...
          int [,]x = new int[2,10]; // both rows have 10 columns.

          Regards Senthil _____________________________ My Blog | My Articles | WinMacro

          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