C# pointers Tutorial with Examples

C# pointers Tutorial with Examples

Today, We want to share with you C# pointers Tutorial with Examples.
In this post we will show you Basics Of Pointers In C#, hear for how to use pointer in c# we will give you demo and example for implement.
In this post, we will learn about Pointers on pointers – C# tutorial with an example.

Introduction: Pointers In C#

In this post, we will learn about  Pointers In C# with example.

Now in this post, I will explain about Pointers In C# with appropriate example.A pointer is simply a type of variable whose value is the address of another variable. Pointers Variable cannot be used directly.

READ :  Vue js upload file-Image upload and move using Laravel

To use a pointer, we need to define the block of code for it. The ‘unsafe’ keyword defines the scope to use pointer variables.Pointer variables can only be used inside an unsafe code block in the program.

how to use pointer in c#
For example,
int* num; // ‘num’ is a pointer to an Integer
char* b; // ‘b’ is a pointer to an Char
float* pi; // ‘pi’ is a pointer to an Float

Now, create Console Application in Visual Studio and write below line of code in it.

using System;

namespace Infinityknow
class Program
static unsafe void Main(string[] args)
// variable ‘p1’ of int type is initialised with value 100
int p1 = 50;

READ :  AngularJS Controllers Inheritance - angular inherits Example

// pointer variable ‘q1’ contains the address of variable ‘p1’ and, ‘&’ used to obtain address of a variable
int* q1 = &p1;

Console.WriteLine(“Value: ” + p1);
Console.WriteLine(“Address: ” + (int)q1);



Value: 50

Address: 122743465
  1. Use of unsafe code may increase security risks.
  2. we have to make a compromise with the automatic garbage collector while using pointer.

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Pointers In C# – C# Tutorials.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

READ :  Angular Built in Functions

Leave a Reply

Your email address will not be published. Required fields are marked *