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 members—they'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++: ...

Get Microsoft® Visual C#® .NET 2003 Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.