Arrays in c#
-
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() :( -
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() :( -
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.
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) -
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)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 -
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)In C# you would just do
int[] array = new int[64]; ... BitMangle(array, 8);
and the BitMangle method would be something likevoid BitMangle(int[] array, int offset) { for (int i=offset; i<array.Length; i++) { // do something with array[i] } }
-
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() :(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