Declaring Parameters

A method can accept zero or more parameters, which mainly act as inputs to a method, in particular to communicate additional state to it. When no parameters are required, an empty pair of parentheses is still required:

static void PrintUsage(){    Console.WriteLine("Usage:  echo <name>");}

If one or more parameters are required, the parameter list is a comma-separated list of distinctly named parameters, prefixed with a type and optional modifiers.

Note: Parameter or Argument?

Terms that are often confused and incorrectly used interchangeably are parameter and argument. The distinction is quite simple, though. Parameters live on a declaration site (for example, in the parameter list of a method), ...

Get C# 5.0 Unleashed 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.