// Error! WriteLine() is not an instance level method!
Console c = new Console();
c.WriteLine("I can't be printed...");
but instead simply prefix the type name to the static WriteLine() member:
// Correct! WriteLine() is a static method.
Console.WriteLine("Thanks...");
Simply put, static members are items that are deemed (by the type designer) to be so common-
place that there is no need to create an instance of the type when invoking the member. While any
class (or structure) can define static members, they are most commonly found within “utility
classes.” For example, if you were to use the Visual Studio 2008 object browser (via the View ➤
Object Browser menu item) and examine the members of System.Console, System.Math,
System.Environment, or System.GC (to name a few), you will find that all of their functionality is
exposed from static members.
Do'stlaringiz bilan baham: |