3.2. C# Enhancements

C# 2010 introduces two useful features that have been present in VB for a long time: optional and named parameters (technically two separate features but often found together).

3.2.1. Named and Optional Parameters

Named parameters allow you to pass parameters into a function in any order and are near essential when using C#'s other new feature: optional parameters. To use a named parameter, simply specify the parameter name followed by a colon and then the value you are passing into a function. The following code illustrates passing the value 1 to a method's Copies parameter, COLOR to the ColorMode parameter, and readme.txt to DocumentName:

Print(Copies:1,ColorMode:"COLOR",DocumentName:"readme.txt"); static void Print(string ...

Get Introducing .NET 4.0: with Visual Studio 2010 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.