O'Reilly logo

C# Quick Syntax Reference by Mikael Olsson

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

CHAPTER 9

image

Methods

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.Write("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, which are methods defined ...

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