C# Program to Print the Size of Various Data Types

Tutorialsrack 01/12/2019 C# Programs

In this C# program, we will learn how to write a program to print the size of various data types.

Here is the code of the program to print the size of various data types:

Code - C# Program To Print the Size of Various Data Types
using System;

namespace Tutorialsrack
    class Program
        /* C# program to print size of various data types */
        static void Main(string[] args)
            Console.WriteLine("sizeof(byte): {0} byte", sizeof(byte));
            Console.WriteLine("sizeof(bool): {0} byte", sizeof(bool));
            Console.WriteLine("sizeof(char): {0} bytes", sizeof(char));
            Console.WriteLine("sizeof(Int16): {0} bytes", sizeof(Int16));
            Console.WriteLine("sizeof(Int32) or sizeof(int): {0} bytes", sizeof(Int32));
            Console.WriteLine("sizeof(Int64): {0} bytes", sizeof(Int64));
            Console.WriteLine("sizeof(float): {0} bytes", sizeof(float));
            Console.WriteLine("sizeof(long): {0} byte", sizeof(long));
            Console.WriteLine("sizeof(double): {0} bytes", sizeof(double));
            Console.WriteLine("sizeof(decimal): {0} bytes", sizeof(decimal));

            //Hit ENTER to exit the program

sizeof(byte): 1 byte
sizeof(bool): 1 byte
sizeof(char): 2 bytes
sizeof(Int16): 2 bytes
sizeof(Int32) or sizeof(int): 4 bytes
sizeof(Int64): 8 bytes
sizeof(float): 4 bytes
sizeof(long): 8 byte
sizeof(double): 8 bytes
sizeof(decimal): 16 bytes

Related Posts


Recent Posts