C# Program to Check a Specified Type is a Pointer or not
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#
using System;
using System.Reflection;
class GFG{
static void Main()
{
int [] var1 = new int [5];
string var2 = "GeeksforGeeks" ;
float var3 = 3.45f;
Console.WriteLine(var1.GetType().IsPointer);
Console.WriteLine(var2.GetType().IsPointer);
Console.WriteLine(var3.GetType().IsPointer);
}
}
|
Output:
False
False
False
Example 2:
C#
using System;
using System.Reflection;
class GFG{
static void Main()
{
int [] array1 = new int [7];
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
Last Updated :
28 Nov, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...