top button
Flag Notify
Site Registration

What are pointer types in C#?

0 votes
219 views
What are pointer types in C#?
posted May 23, 2017 by Madhavi Kumari

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Any of the following types may be a pointer type:

  1. sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
  2. Any enum type.
  3. Any pointer type.
  4. Any user-defined struct type that contains fields of unmanaged types only.

Pointer types do not inherit from object and no conversions exist between pointer types and object. Also, boxing and unboxing do not support pointers. However, you can convert between different pointer types and between pointer types and integral types.
When you declare multiple pointers in the same declaration, the asterisk (*) is written together with the underlying type only; it is not used as a prefix to each pointer name. For example:

int* p1, p2, p3;   // Ok  
int *p1, *p2, *p3;   // Invalid in C#  

A pointer cannot point to a reference or to a struct that contains references, because an object reference can be garbage collected even if a pointer is pointing to it. The garbage collector does not keep track of whether an object is being pointed to by any pointer types.
The value of the pointer variable of type myType* is the address of a variable of type myType.

answer May 24, 2017 by Shweta Singh
...