Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Is this a pointer operation ?

Is this a pointer operation ?

Scheduled Pinned Locked Moved C#
questioncsharp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?

    L A B 3 Replies Last reply
    0
    • L Lost User

      I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      desmond5 wrote: True ? yes :) top secret

      1 Reply Last reply
      0
      • L Lost User

        I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?

        A Offline
        A Offline
        Andy Wieberneit
        wrote on last edited by
        #3

        If your C++ code is managed C++: yes, in fact it is. If your C++ code is unmanaged C++: no, it's not the same. Pointers in managed C++ are managed by the garbage collector, as are the reference types in C#. Hence you don't have to (and you will not be able to)delete them manually. Pointers in unmanaged C++, however, are completely at your mercy, so you have to take care of them via the delete operator.

        1 Reply Last reply
        0
        • L Lost User

          I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?

          B Offline
          B Offline
          Bryan White
          wrote on last edited by
          #4

          Yes (but maybe no, if UserTri is actually a value type (like struct) rather than 'true' class). I'm an Assembler programmer at heart, and in cases like this, ask myself, "Is this storing an address (of, say, 4 bytes), or the value?" The C++ code is storing an address. The C# code stores address of classes & copy of variable for value types (simple data types & structs). I LOVE pointers, and regard C#'s reference (and C++'s, for that matter) as 'pointers in disguise'. Regards Brewman

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups