- Creating Classes
- Creating Objects
- Using Access Modifiers
- Creating Fields and Using Initializers
- Creating Methods
- Creating Properties
- Read-only Properties
- Creating Constructors
- Creating Structs
- Creating Static Members
- Creating Static Fields
- Creating Static Properties
- Creating Destructors and Handling Garbage Collection
- Overloading Methods
- Overloading Operators
- Creating Namespaces
- In Brief
Creating Static Members
So far, the fields, methods, and properties we've been creating have all been members of objects. You can also create fields, methods, and properties that you use with classes directly, not with objects. These members are called static members, also called class members (not object members), and you use them with the class name, not the name of an object.
As you know, Main is declared static so that C# itself can call it without creating an object from your main class. That's the way it works with all static membersthey're intended to be used with the class, not with an object. We'll take a look at creating static members now, starting with static fields.
For C++ Programmers
Here's a big difference between C# and C++: in C#, you cannot access static members of a class using an object of that class, as you can in C++. You must use the class name to access static members, not an object.