4.4. Methods

You use methods to query and modify the state of the objects. In OOP, method calls are the preferred way to interact with objects. Most class members are methods, so we've adapted the following recommended guidelines for method usage from the Visual Studio help files:

  • Method names should be verbs or verb phrases and in Pascal case (unlike the Camel casing of Java).

  • Do not use Hungarian notation.

  • By default, methods are nonvirtual.

The method signature indicates the return type, any access modifiers or qualifiers preceding the method name, method parameters, and any exceptions that the method throws.

The following access modifiers are typically used in front of C# methods.

4.4.1. public

A public method of an object can be called by ...

Get .NET for Java Developers: Migrating to C# now with O’Reilly online learning.

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