Multiple choice technology platforms and products

Which of the following does not apply to new feature Optional parameters in C# 4.0

  1. Optional parameters can make your code more readable and easier to maintain, and can reduce the amount of typing you have to do

  2. We can use optional parameters and no longer have to overload functions with a number of methods

  3. Optional parameters are created in C# by specifying a default value and must appear after required parameters

  4. Following is the way to specify optional parameters for function ReadFile static void ReadFile(string FileName:"", string OpenMode:"ReadOnly") {...}

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Optional parameters in C# use the syntax parameterName = defaultValue, not parameterName: defaultValue. The colon syntax shown in option D is incorrect and would cause a compilation error. Options A, B, and C correctly describe the benefits and syntax rules for optional parameters.