-2

Some C code

#include aes.h

void encryption(unsigned char aes_key[16], unsigned char _buff[16], unsigned char _iv[16]){

unsigned long encrypt = 1;
unsigned char output[];

AES_set_encrypt_key(aes_key, 128, &key);
for(i = 0; i > 16 ; i ++){
       AES_cbc_encrypt(&_buff[i], output, 16, &key, _iv, encrypt);
       }
 }

How to do '&_buff[i]' in C#? I've been trying to use

_buff[i]

in C# but it gives different result. Does anyone know how to do this? It would be big help.

gforce1992
  • 11
  • 2
  • 4
    We need more context. What are you specifically trying to do? – Dave Zych Jun 03 '15 at 02:09
  • 4
    Thats the address-of operator in C, and without context about what you are trying to do, its hard to say if you need it. 99% of the time you don't need pointers and address-of in c# – Ron Beyer Jun 03 '15 at 02:13

1 Answers1

0

I think you are looking for these search terms: C# string pass by reference

That C code is actually wrong and a bad example. In general, you can pass a string in order to change it. See the example below with change(buf). Also change(&buf[0]) will work, but it's weird. Or you can say change(buf+3), this will change the string beginning at 3rd character.

void change(char *buf){
    strcpy(buf, "changed");
}

int main(){
    char buf[50];
    strcpy(buf, "0123456789");
    change(buf);// result => buf = "chagned"
    //change(&buf[0]);//result => buf = "chagned"
    //change(buf + 3);//result => buf = "012changed"
    printf("%s\n", buf);
    return 0;
}

And then there is buf[0] which is a single character. It's different than &buf[0]

Community
  • 1
  • 1
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77