Chapter 11

Improving Productivity with Named and Optional Parameters

IN THIS CHAPTER

check Distinguishing between named and optional parameters

check Using optional parameters

check Implementing reference types

check Declaring output parameters

Parameters, as you probably remember, are the inputs to methods. They’re the values that you put in so that you get a return value. Sometimes, the return values are parameters, too, which confuses things.

In older versions of C# and most C-derived languages, parameters can't be optional. Instead of making parameters optional, you are required to make a separate overload for every version of the method you expect your users to need. This pattern works well, but there are some problems that are explored in this chapter. Many VB programmers point to flexible parameterization as a strong reason to use VB over C#.

C# 4.0 and above have optional parameters. Optional parameters are parameters that have a default value right in the method signature — just like the VB.NET implementation. This is one more step toward language parity, and again in the name of COM programming. ...

Get C# 7.0 All-in-One For Dummies 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.