Method Invocation

Keeping the best for the (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, ...

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