omg..i was excited about having pointers in c# but then i try to use them and i get the message that strings and objects cant have pointers pointing them...seems i can only with ints? omg....this must be a joke!
Printable View
omg..i was excited about having pointers in c# but then i try to use them and i get the message that strings and objects cant have pointers pointing them...seems i can only with ints? omg....this must be a joke!
Post the code. Also did you have the unsafe keyword?
yea i did
code was something like this
string test = "............";
string* ptr = &test;
You cant use managed types with unsafe code, so you will have problems with the string. I remember during my C++ days, there was'nt a built in string type, so we would have to use a char array to simulate a string. However there were various string libraries. Anyway here is an example
As you can see, string is treated differently than the other types.Code:char *test = stackalloc Char[20];
test[0]= 'T';
test[1]= 'e';
test[2]= 's';
test[3]= 't';
char *ptr = test;
MessageBox.Show(ptr->ToString());
the -> isnt allowed by C#...! i think
hm worked...damn where can i get a good tuturial about pointers in C# on the net? or even in a book?
or they work just like c++ ones? i am starting with c++ and if they work just like c++ ones then i should not need a new book about it!
They should work like in C++. However there are some keyword to make note of when working with pointers, like fixed and stackalloc. There are a couple more. Other than that it should be ok to transfer what ou learned in C++ to c# when dealing with pointers. The most problems you are going to have is when you are dealing with strings.
Good luck
Look up unsafe code, tutorial (C#) in MSDN for some useful examples on pointers.
k tk u all