7.2. Method basics

I shall cover method structure and method parameters before going into other aspects of methods.

7.2.1. Method structure

A C# method is structured in the same way as a Java method: [1]

[1] The textbook definition of 'method signature' in C# comprises only of the method identifier (the name) and the type and kind (reference, value or output) of its parameters. All modifiers and the method's return type are not considered to be part of the method signature. The params keyword, if used in the parameter list, is also not part of the signature.

[assess_modifier][other_modifiers] return_type
method_name ([parameter(s)]){
  //method code
}

For example, the method:

private void DoThis (int j, string s, object o){ }

takes in three ...

Get From Java to C#: A Developer's Guide 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.