Defining Methods

A method can be defined as either a static or an instance member, which influences what state is available to it. You’ve seen the use of a special static method plenty of times, namely an application’s entry point Main method:

class Program{    static void Main(string[] args)    {        ...    }}

Of the modifiers available on a method declaration, we’ve only used the static one. Many other modifiers exist to specify things such as visibility (public, private, internal, and the object-oriented [OO]-related protected and protected internal access modifiers). You’ll see more of those modifiers in Chapter 14, “Object-Oriented Programming,” including abstract, virtual, override, sealed, and new.

The declaration of a method consists ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.