O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required