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. Arrays in c#

Arrays in c#

Scheduled Pinned Locked Moved C#
csharpc++data-structuresquestion
6 Posts 5 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.
  • C Offline
    C Offline
    cheesepirate
    wrote on last edited by
    #1

    I'm feeling a little dense here, but how do i do the C equivalent of int array [16]; int * p = array + 8; I've tried to look at the managed C++, but the program I'm using to convert to C# keeps crashing when I try to look at main() :(

    L L 2 Replies Last reply
    0
    • C cheesepirate

      I'm feeling a little dense here, but how do i do the C equivalent of int array [16]; int * p = array + 8; I've tried to look at the managed C++, but the program I'm using to convert to C# keeps crashing when I try to look at main() :(

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Pointer manipulation requires an unsafe block around your code. However, depending on what you want to do with p, there might be a better managed solution than dropping into unsafe code.

      C 1 Reply Last reply
      0
      • L Lost User

        Pointer manipulation requires an unsafe block around your code. However, depending on what you want to do with p, there might be a better managed solution than dropping into unsafe code.

        C Offline
        C Offline
        cheesepirate
        wrote on last edited by
        #3

        Hmm, I think I'de prefer safe rather than sorry :) Basically, I'm wanting to do something along these lines int array [64]; ... // Do something to array ... BitMangle (array + 8) // Do some sort of operation to the last 56 ints I come from a really heavy C/C++ background and I'm trying to get to grips with C# - I'm getting most of it, but this one little thing has me! (ps - If there are some good book/articles I should read, do tell me)

        N B 2 Replies Last reply
        0
        • C cheesepirate

          Hmm, I think I'de prefer safe rather than sorry :) Basically, I'm wanting to do something along these lines int array [64]; ... // Do something to array ... BitMangle (array + 8) // Do some sort of operation to the last 56 ints I come from a really heavy C/C++ background and I'm trying to get to grips with C# - I'm getting most of it, but this one little thing has me! (ps - If there are some good book/articles I should read, do tell me)

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          cheesepirate wrote: (ps - If there are some good book/articles I should read, do tell me) You should read through the Arrays Tutorial[^] which covers single, multidimensional and jagged arrays in the C# Programmer's Reference. - Nick Parker
          My Blog | My Articles

          1 Reply Last reply
          0
          • C cheesepirate

            Hmm, I think I'de prefer safe rather than sorry :) Basically, I'm wanting to do something along these lines int array [64]; ... // Do something to array ... BitMangle (array + 8) // Do some sort of operation to the last 56 ints I come from a really heavy C/C++ background and I'm trying to get to grips with C# - I'm getting most of it, but this one little thing has me! (ps - If there are some good book/articles I should read, do tell me)

            B Offline
            B Offline
            Bret Mulvey
            wrote on last edited by
            #5

            In C# you would just do int[] array = new int[64]; ... BitMangle(array, 8); and the BitMangle method would be something like void BitMangle(int[] array, int offset) {    for (int i=offset; i<array.Length; i++)    {       // do something with array[i]    } }

            1 Reply Last reply
            0
            • C cheesepirate

              I'm feeling a little dense here, but how do i do the C equivalent of int array [16]; int * p = array + 8; I've tried to look at the managed C++, but the program I'm using to convert to C# keeps crashing when I try to look at main() :(

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              cheesepirate wrote: int * p = array + 8; Sorry but that bad code in any language! what is 8? 2 or 4 ints? I mean any compiler could produce wrong code for that! Now if you did the following, life would be different, and at least someone else can understand the code.

              int array [16];
              int * p = &array[2];

              And I can almost gaurentee you, that that will work now via MC++. top secret xacc-ide 0.0.1

              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