Pointers are widely used for fast execution of a program as pointer allow you to easily write low level code. Simply we can say, A Pointer is a memory variable that holds up the address of another variable. In spite of such great thing poses by pointer it is not supported in C# inherently, however they can be used in unsafe code- the code that is marked as unsafe.
We can mark a piece of our program code to unsafe by creating a block using unsafe keyword and putting that code inside the unsafe block. A piece of program code is considered to be type safe if it is accessing other piece of code using only interfaces. Therefore if your program contains some code that has been marked as unsafe, then C# compiler does not compile your program code until you explicitly tell the compiler to skip the type safety checking.
How you gonna do this
Well one way to skip the type safety checking is to use the C# command line compiler utility that is – csc.exe, to compile the C# source code and specify the unsafe keyword while computing the C# source code.
Creating Pointer in Console
Step 1: Open Visual Studio. By pressing Ctrl +Shift + N you will get your “New Project” Window.

Step 2: After pressing OK you will get into your Coding Part where you will see three files in Solution Explorer [Properties, References, Program.cs], in which Program.cs file is your main file where you embed all your Inheritance program code.

- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace consolepointer
- {
- class Program
- {
- unsafe static void Main(string[] args)
- {
- int number = 200;
- int* merapointer;
- merapointer = &number;
- Console.WriteLine("Value of Number:" + number);
- Console.WriteLine("Value of MeraPointer:"+(int)merapointer);
- Console.ReadKey();
- }
- }
- }






Arul RPosted Oct 28, 2015, 5:28 AM
Good one !!!
Priyaranjan K SPosted Oct 19, 2015, 12:43 PM
Nice article ..
Gowtham KPosted Oct 19, 2015, 12:22 PM
Good One
Rajeesh MenothPosted Oct 19, 2015, 11:44 AM
Thanks for sharing!
Sourabh SomaniPosted Oct 19, 2015, 10:27 AM
Clean and nice explaination but never used in any application...
Sibeesh VenuPosted Oct 19, 2015, 8:53 AM
Nice Share
Mukesh KumarPosted Oct 19, 2015, 8:24 AM
Good Job Sir
Harshad PansuriyaPosted Oct 19, 2015, 6:31 AM
Nice work