Skip to content
Related Articles

Related Articles

C# Program to Check a Specified Type is a Pointer or not

Improve Article
Save Article
Like Article
  • Last Updated : 28 Nov, 2021

A pointer is a variable that contains the references of another variable. Or in other words, the pointer is a variable that stores the address of the same type of variable. For example, a string pointer can store the address of a string. In C#, we can able to check the given type is a pointer or not by using the IsPointer property of the Type class. This property returns true if the specified type is a pointer. Otherwise, it will return false. It is a read-only property.

Syntax:

public bool IsPointer{ get; }

Example 1:

C#




// C# program to check whether
// the given type is pointer or not
using System;
using System.Reflection;
  
class GFG{
      
static void Main()
{
      
    // Create an array with 5 elements of integer type
    int[] var1 = new int[5];
    string var2 = "GeeksforGeeks";
    float var3 = 3.45f;
      
    // Check the type is pointer or not
    // Using IsPointer property
    Console.WriteLine(var1.GetType().IsPointer);
    Console.WriteLine(var2.GetType().IsPointer);
    Console.WriteLine(var3.GetType().IsPointer);
}
}

Output:

False
False
False

Example 2:

C#




// C# program to check whether
// the given type is pointer or not
using System;
using System.Reflection;
  
class GFG{
      
static void Main()
{
      
    // Create an array of integer type with 7 elements
    int[] array1 = new int[7];
      
    // Check the type is pointer or not
    // Using IsPointer property
    if (array1.GetType().IsPointer == true)
    {
        Console.WriteLine("The given type is a pointer");
    }
    else
    {
        Console.WriteLine("The given type is not a pointer");
    }
}
}

Output:

The given type is not a pointer

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!