Introduction
C# .net does not allow to pointer in safe
mode. If you are use pointer in c# program , then you are declare an entire
method as unsafe. steps of compiling unsafe code-
- Go to solution explorer and double click
to property.
-select build tab.
-select allow unsafe code and then compile
your program.
Example
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
use_pointer_in_c_sharp
{
class
Program
{
public
static
void Main()
{
unsafe
//declare unsafe mode
{
int number
= 10;
int*
Pointer = &number;
// create
pointer & value of pointer is address of number
Console.WriteLine("Number
is : {0} ",
number);
Console.WriteLine("Memory
Address is: {0} ", (int)Pointer);//show
address of number
}
Console.ReadKey();
}
}
}
Output: