© Mikael Olsson 2018
Mikael OlssonC# 7 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-3817-2_9

9. Methods

Mikael Olsson1 
(1)
Hammarland, Länsi-Suomi, Finland
 

Methods are reusable code blocks that will only execute when called.

Defining Methods

A method can be created inside a class by typing void followed by the method’s name, a set of parentheses, and a code block. The void keyword means that the method will not return a value. The naming convention for methods is the same as for classes—a descriptive name with each word initially capitalized.
class MyApp
{
  void MyPrint()
  {
    System.Console.WriteLine("Hello World");
  }
}

All methods in C# must belong to a class, and they are the only place where statements may be executed. C# does not have ...

Get C# 7 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library 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.