C# - Check a Specified Type is an Array or Not?

Learn, how to check a specified type is an array or not in C#?
Submitted by Nidhi, on October 30, 2020 [Last updated : March 22, 2023]

Checking a type is an array or not

Here, we will check a specified type is an array or not using the IsArray property.

C# program to check a specified type is an array or not

The source code to check a specified type is a pointer or not is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# - Check a Specified Type is an Array or Not?.

using System;
using System.Reflection;

class Program
{
    static void Main()
    {
        int[] Arr = new int[10];

        if (Arr.GetType().IsArray == true)
        {
            Console.WriteLine("Arr is an array");
        }
        else
        {
            Console.WriteLine("Arr is not an array");
        }
    }
}

Output

Arr is an array
Press any key to continue . . .

Explanation

In the above program, we created a class Program that contains the Main() method. The Main() method is the entry point for the program. Here we check the specified type is an array or not using the IsArray property and then printed the appropriate message on the console screen.

C# Basic Programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.