Home  >  Article  >  Backend Development  >  What are pointers in C#?

What are pointers in C#?

王林
王林forward
2023-09-02 11:49:021414browse

C# 中的指针是什么?

A pointer is a variable whose value is the address of another variable, which is the direct address of a memory location.

The syntax for a pointer is -

type *var-name;

Here's how to declare a pointer type -

double *z; /* pointer to a double */

C# allows the use of pointer variables in functions or blocks of code marked by the unsafe modifier. Unsafe code or unmanaged code is a block of code that uses pointer variables.

The following is our module showing how to declare and use pointer variables. We have used the unsafe modifier here -

static unsafe void Main(string[] args) {
   int val = 50;
   int* x = &val;

   Console.WriteLine("Data: {0} ", val);
   Console.WriteLine("Address: {0}", (int)x);
   Console.ReadKey();
}

The above is the detailed content of What are pointers in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete