LFInteractive Docs
  • Programming Documentation
  • C#
    • Installing Visual Studio
    • Understanding C#
      • Namespaces
      • Classes
      • Enum
      • Variables
        • Static Types
        • Primitive Types
        • Access Modifiers
        • Variables vs Properties
        • Nullable Variables
      • Getters and Setters
      • Solution vs Project
      • Struct vs Class
      • Coding Conventions
      • Tasks and Async
        • Parallel Tasks
      • Methods
      • PreProcessor Statements
    • Creating Your First Console App
      • Class Library
        • Models
          • File Model
          • Result Model
        • Controllers
          • File Controller
          • File System Controller
      • Console App
        • Nuget Packages
        • Main Method
    • Minecraft.NET
      • Minecraft.NET Library
      • Modrinth.NET Library
      • CurseForge.NET Library
      • Fabric.NET Library
    • Common Lib
      • Strings
      • Advanced Network Client
      • Advanced Timer
      • Advanced File Info
      • Configuration File
      • Application Config
      • Database File
      • Crypt Class
  • C++
    • Networking
      • Windows Socket (Client)
    • cclip
    • VCPKG
    • spdlog
      • Getting Started
      • Patterns
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. C#
  2. Understanding C#
  3. Variables

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.

PreviousStatic TypesNextAccess Modifiers

Last updated 1 year ago

Was this helpful?