What is the difference between a C# Reference and a Pointer?

后端 未结 10 1866
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 21:45

I do not quite understand the difference between a C# reference and a pointer. They both point to a place in memory don\'t they? The only difference I can figure out is that

10条回答
  •  暖寄归人
    2020-11-28 22:12

    Pointers point to a location in the memory address space. References point to a data structure. Data structures all moved all the time (well, not that often, but every now and then) by the garbage collector (for compacting memory space). Also, as you said, data structures without references will get garbage collected after a while.

    Also, pointers are only usable in unsafe context.

提交回复
热议问题