© Mikael Olsson 2020
Mikael OlssonC# 8 Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-5577-3_9

9. Methods

Mikael Olsson
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 global functions, ...

Get C# 8 Quick Syntax Reference: A Pocket Guide to the Language, APIs, and Library now with O’Reilly online learning.

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