pointer

  • Thread starter Thread starter Joy Maitland
  • Start date Start date
J

Joy Maitland

is pointer really use often in C#?

I am from a Java background and not getting used to pointers.
 
is pointer really use often in C#?

No, they are used rarely and are actively discouraged. They step outside the
bounds of managed code and as such can only be used in blocks marked with
the "unsafe" keyword. If you NEED to use them (and there are valid
situations) then you can, but most of the time there are managed equivalents
to do what you might want to do.
 
Pointers in C# are only used for unmanaged code. They are not tracked by
the garbage collector. I can't say they're rarely used but they're definetly
not as common as in other languages.
 
No, they are used rarely and are actively discouraged. They step outside the
bounds of managed code and as such can only be used in blocks marked with
the "unsafe" keyword. If you NEED to use them (and there are valid
situations) then you can, but most of the time there are managed equivalents
to do what you might want to do.

Maybe a nitpick - but pointers in C#, are not stepping out of bounds of
managed code... The code is still IL and is managed code. The difference is
that code IL generated in an unsafe context is not verifiable by the runtime
as being safe for execution. I know, probably just semantics - but, I just
couldn't resist :)
 
Kenneth said:
Pointers in C# are only used for unmanaged code. They are not tracked
by the garbage collector. I can't say they're rarely used but they're
definetly not as common as in other languages.

This is wrong, read Tom's reply.
 
Tom said:
Maybe a nitpick - but pointers in C#, are not stepping out of bounds of
managed code... The code is still IL and is managed code.

Well the code is managed, but the pointers themself are stepping out of
the bounds, i.e. they are pointing something that is not managed.
 
Well the code is managed, but the pointers themself are stepping out of
the bounds, i.e. they are pointing something that is not managed.

Not neccesarily. You can have pointer to managed memory.
 
Tom said:
Not neccesarily. You can have pointer to managed memory.

Yes, you are right. But even if the pointers are in IL and in managed
code, they can point to memory that is not managed. Ok ?
 
Back
Top