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 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.