C# Program to Check a Specified Type is a Pointer or not (original) (raw)
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
Similar Reads
- C# Program to Check a Specified Type is a Class or Not A class is a collection of methods, variables, and objects. Or we can say that a class is a blueprint using which an object is created. So to check whether the specified type is a class as well as delegates or not we use the IsClass property of the Type class. It will return true if the type is clas 2 min read
- C# Program to Check a Specified Type is Nested or not In programming languages, nested means a class or a method or loop or structure is present inside another class or a method or loop or structure. In C#, we can check a specified type is nested or not using the IsNested property of the Type class. This property returns a value that represents whether 2 min read
- C# Program to Check a Specified Type is an Array or Not In C#, an array is a group of homogeneous elements that are referred to by a common name. So in this article, we will discuss how to check the variable is of array type or not. To do this task, we use the IsArray property of the Type class. This property is used to determine whether the specified ty 2 min read
- C# Program to Check a Specified Type is a Primitive Data Type or Not In C#, data types are used to specify the type of data that a variable can hold. There are two types of data types available in C# that is, primitive and non-primitive data types. Primitive data types are predefined data types such as Byte, SByte, Boolean, Int16, UInt16, Int32, UInt32, Char, Double, 2 min read
- C# Program to Check a Specified Type is Public or not A class is a collection of methods, variables, and objects. We can create a public class, private class, or protected class using the access modifiers. A class created with the public modifier will have access entirely to a program. So to check whether the given class or type is a public type or not 2 min read
- C# Program to Check a Specified Type is an Interface or not The interface is just like a class, it can also have methods, properties, events, etc. as its members, but it only contains the declaration of the members and the implementation of these members will be given by the class that implements the interface implicitly or explicitly. We can check the speci 2 min read
- C# Program to Check a Specified Type is a Value Type or Not In C#, the value type represents a sequence of bits. It is not a class or an interface, it is referred to as a struct or enum(a special case of value type). So to check whether the specified type is Value Type or not we use the IsValueType property of the Type class. It is a read-only property. It w 2 min read
- C# Program to Check a Class is a Sub-Class of a Specified Class or Not A class is a collection of methods, variables, and objects. A subclass is a class that is extended from the parent class. It should achieve all the properties from the parent class. Its syntax is similar to a class. Using: operator we can create the subclass. We can check the class is a subclass of 2 min read
- C# Program to Check a Specified Class is an Abstract Class or Not Abstraction is the process to hide the internal details and showing only the functionality. The abstract keyword is used before the class or method to declare the class or method as abstract. In this article, we will learn how to check a specified class is an abstract class or not. To do this task w 2 min read
- Types of Pointer in Programming Pointers in programming are variables that store the memory address of another variable. There are several types of pointers, including Null pointer, Void pointer, Wild pointer, Dangling pointer, Complex pointer, Near pointer, Far pointer, and Huge pointer. Each type has its characteristics and uses 15 min read