Primitive Types

Primitive types are basic data types built into the language that represent fundamental values. They are used to store and manipulate simple values directly without relying on more complex objects. Here are the different primitive types in C# with examples:

  1. bool: Represents a Boolean value that can be either true or false. Example:

    bool isReady = true;
  2. byte: Represents an 8-bit unsigned integer ranging from 0 to 255. Example:

    byte age = 27;
  3. sbyte: Represents an 8-bit signed integer ranging from -128 to 127. Example:

    sbyte temperature = -10;
  4. short: Represents a 16-bit signed integer ranging from -32,768 to 32,767. Example:

    short population = 5000;
  5. ushort: Represents a 16-bit unsigned integer ranging from 0 to 65,535. Example:

    ushort count = 10000;
  6. int: Represents a 32-bit signed integer ranging from -2,147,483,648 to 2,147,483,647. Example:

    int score = 100;
  7. uint: Represents a 32-bit unsigned integer ranging from 0 to 4,294,967,295. Example:

    uint distance = 5000;
  8. long: Represents a 64-bit signed integer ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. Example:

    long population = 7500000000;
  9. ulong: Represents a 64-bit unsigned integer ranging from 0 to 18,446,744,073,709,551,615. Example:

    ulong bigNumber = 9999999999;
  10. float: Represents a single-precision 32-bit floating-point number. Example:

    float pi = 3.14f;
  11. double: Represents a double-precision 64-bit floating-point number. Example:

    double distance = 1500.75;
  12. decimal: Represents a decimal number with higher precision for financial and monetary calculations. Example:

    decimal amount = 99.99m;
  13. char: Represents a single Unicode character. Example:

    char grade = 'A';
  14. string: Represents a sequence of characters. Example:

    string name = "John Doe";

These primitive types provide a range of options to store and manipulate different kinds of data, including numeric values, Boolean values, characters, and strings. They are the building blocks of more complex data structures and are widely used in C# programming.

Last updated

Was this helpful?