What is Data Types With Example Code

In C#, there are several built-in data types that you can use to declare variables.
Here are the most common ones along with examples
These are the fundamental data types in C#.
Depending on your requirements, you choose the appropriate data type to store your data.





using System;
 
class Program
{
    static void Main(string[] args)
    {
        // Integral Types
        byte myByte = 10;           // Represents unsigned integers with values ranging from 0 to 255.
        sbyte mySByte = -10;        // Represents signed integers with values ranging from -128 to 127.
        short myShort = -1000;      // Represents signed integers with values ranging from -32,768 to 32,767.
        ushort myUShort = 1000;     // Represents unsigned integers with values ranging from 0 to 65,535.
        int myInt = -100000;        // Represents signed integers with values ranging from -2,147,483,648 to 2,147,483,647.
        uint myUInt = 100000;       // Represents unsigned integers with values ranging from 0 to 4,294,967,295.
        long myLong = -10000000000; // Represents signed integers with values ranging from approximately -9.2 x 10^18 to 9.2 x 10^18.
        ulong myULong = 10000000000;// Represents unsigned integers with values ranging from 0 to approximately 18.4 x 10^18.
 
        // Floating Point Types
        float myFloat = 3.14f;      // Represents single-precision floating-point numbers.
        double myDouble = 3.14159;   // Represents double-precision floating-point numbers.
        decimal myDecimal = 3.1415926535897932384626433832m; // Represents decimal numbers with 28-29 significant digits.
 
        // Character Type
        char myChar = 'A';          // Represents a single Unicode character.
 
        // Boolean Type
        bool myBool = true;         // Represents a Boolean value (true or false).
 
        // String Type
        string myString = "Hello, world!"// Represents a sequence of characters.
 
        // Object Type
        object myObject = 42;       // Represents any type in C#. It is the ultimate base class of all other types.
 
        // Output
        Console.WriteLine($"byte: {myByte}");
        Console.WriteLine($"sbyte: {mySByte}");
        Console.WriteLine($"short: {myShort}");
        Console.WriteLine($"ushort: {myUShort}");
        Console.WriteLine($"int: {myInt}");
        Console.WriteLine($"uint: {myUInt}");
        Console.WriteLine($"long: {myLong}");
        Console.WriteLine($"ulong: {myULong}");
        Console.WriteLine($"float: {myFloat}");
        Console.WriteLine($"double: {myDouble}");
        Console.WriteLine($"decimal: {myDecimal}");
        Console.WriteLine($"char: {myChar}");
        Console.WriteLine($"bool: {myBool}");
        Console.WriteLine($"string: {myString}");
        Console.WriteLine($"object: {myObject}");
    }
}