Results 1 to 9 of 9

Thread: C# and pointers

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    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/

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Post the code. Also did you have the unsafe keyword?
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yea i did

    code was something like this

    string test = "............";
    string* ptr = &test;
    \m/\m/

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  5. #5

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    the -> isnt allowed by C#...! i think
    \m/\m/

  6. #6

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    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/

  7. #7
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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

  8. #8
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    Look up unsafe code, tutorial (C#) in MSDN for some useful examples on pointers.
    -scott
    he he he

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    k tk u all
    \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
  •  



Click Here to Expand Forum to Full Width