×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# - Check a Specified Type is a Value Type or Not?

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

Checking a type is a value type or not

Here, we will check a specified type is a value type or not using the IsValueType property of Type class.

C# program to check a specified type is a value type or not

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

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

using System;
using System.Reflection;

struct Sample
{ 
    public static void Print()
    {
        Console.WriteLine("Print() method called");
    }
}

class Program
{
    static void Main()
    {
        Type type = typeof(Sample);

        if (type.IsValueType == true)
        {
            Console.WriteLine("Sample is value type");
        }
        else
        {
            Console.WriteLine("Sample is not value type");
        }
    }
}

Output

Sample is value type
Press any key to continue . . .

Explanation

In the above program, we created a structure and a class Program. The Sample structure contains a static Method Print(), and the Program class contains the Main() method. The Main() method is the entry point for the program. Here we check the specified type is a value type or not using the IsValueType property of Type class and printed the appropriate message on the console screen.

C# Basic Programs »

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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