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 pointers are not as clever, cannot point to anything on the heap, are exempt from garbage collection, and can only reference structs or base types.
One of the reasons I ask is that there is a perception that people need to understand pointers well (from C, I guess) to be a good programmer. A lot of people who learn higher level languages miss this out and therefore have this weakness.
I just don’t get what is so complex about a pointer? It is basically just a reference to a place in memory is it not? It can return its location and interact with the object in that location directly?
Have I missed a massive point?
C# references can, and will be relocated by garbage collector but normal pointers are static. This is why we use
fixedkeyword when acquiring a pointer to an array element, to prevent it from getting moved.EDIT: Conceptually, yes. They are more or less the same.