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

Static Types

In simple terms, "static" in C# is a keyword that means something belongs to the class itself, rather than to a specific object created from the class. When a member (such as a field, method, or property) is declared as static, it is shared among all instances of the class.

Here's a simplified explanation of what "static" means:

Imagine you have a class called "Car" that represents different cars. Each car object has its own unique characteristics, such as color, model, and mileage. However, there are some things that should be the same for all cars, regardless of their individual properties. For example, the maximum speed limit or the number of wheels.

If you declare a field or method as static within the "Car" class, it means that this field or method is not specific to any particular car object. Instead, it is associated with the class itself and can be accessed or used without creating an instance of the class.

For example, if you have a static field called "maxSpeed" in the "Car" class, it represents the maximum speed limit for all cars. Every car object can access this field and get the same value. Similarly, if you have a static method called "getTotalCars" in the "Car" class, it can be called without creating any car objects and it will return the total number of cars created so far, regardless of their individual properties.

In summary, "static" in C# means something is shared among all instances of a class and is associated with the class itself rather than with individual objects. It allows you to define and access values or behaviors that are not specific to any particular object but are relevant to the class as a whole.

PreviousVariablesNextPrimitive Types

Last updated 1 year ago

Was this helpful?