How to check the data type of a variable in C#

1 Answer

0 votes
using System;

public class VarType
{
    public static void Main(string[] args)
    {
        int a = 242; 
        Console.WriteLine (a.GetType());
        
        object obj = "C#"; 
        Type objType = obj.GetType();
        Console.WriteLine (objType);
        
        double b = 383.023; 
        Console.WriteLine (b.GetType());
        
        string c = "abc";
        Console.WriteLine (c.GetType());
        
        bool d = false;
        Console.WriteLine (d.GetType());
        
        char e = 'a';
        Console.WriteLine (e.GetType());
        
        uint f = 8293481;
        Console.WriteLine (f.GetType());

    }
}


/*
run:

System.Int32
System.String
System.Double
System.String
System.Boolean
System.Char
System.UInt32

*/

 



answered Jul 7, 2024 by avibootz

Related questions

1 answer 82 views
1 answer 68 views
1 answer 82 views
1 answer 83 views
1 answer 74 views
...