Creating Static Members

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.




Microsoft Visual C#. NET 2003 Kick Start
Microsoft Visual C#.NET 2003 Kick Start
ISBN: 0672325470
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net