Method Invocation

Keeping the best for (almost) last: invocation expressions. Methods being the main containers for code—and in fact, properties and indexers are methods in disguise—the most meaningful operation to carry out with them is invocation.

Methods can be called directly or indirectly, the latter case referring to the use of delegates. Either way, invocation syntax has the same shape: an expression followed by a (potentially empty) comma-separated list of arguments between parentheses. You’ve already seen numerous examples:

Console.WriteLine("Hello");string s = person.ToString();int three = calc.Add(1, 2);

All the preceding examples are regular method invocations. A call instruction targeting the method is emitted in the IL code, as ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

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