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