|
-
Jan 3rd, 2003, 09:15 PM
#1
Thread Starter
yay gay
C# and pointers
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!
\m/  \m/
-
Jan 3rd, 2003, 09:37 PM
#2
Frenzied Member
Post the code. Also did you have the unsafe keyword?
Dont gain the world and lose your soul
-
Jan 3rd, 2003, 10:14 PM
#3
Thread Starter
yay gay
yea i did
code was something like this
string test = "............";
string* ptr = &test;
\m/  \m/
-
Jan 3rd, 2003, 11:07 PM
#4
Frenzied Member
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
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());
As you can see, string is treated differently than the other types.
Dont gain the world and lose your soul
-
Jan 4th, 2003, 09:34 AM
#5
Thread Starter
yay gay
the -> isnt allowed by C#...! i think
\m/  \m/
-
Jan 4th, 2003, 09:39 AM
#6
Thread Starter
yay gay
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!
\m/  \m/
-
Jan 4th, 2003, 03:05 PM
#7
Frenzied Member
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
Dont gain the world and lose your soul
-
Jan 4th, 2003, 04:02 PM
#8
Hyperactive Member
Look up unsafe code, tutorial (C#) in MSDN for some useful examples on pointers.
-scott
he he he
-
Jan 4th, 2003, 06:44 PM
#9
Thread Starter
yay gay
\m/  \m/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|