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

后端 未结 10 1858
隐瞒了意图╮
隐瞒了意图╮ 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:16

    C# references can, and will be relocated by garbage collector but normal pointers are static. This is why we use fixed keyword when acquiring a pointer to an array element, to prevent it from getting moved.

    EDIT: Conceptually, yes. They are more or less the same.

提交回复
热议问题