What is the output of: static void Inc(ref int a) => a++; int v = 1; Inc(ref v); Console.WriteLine(v);?
Correct answer D. 2
Topic / 95 questions
Page 4 of C# multiple-choice questions with answers. Tap an option to check yourself.
Page 4 of 5
Correct answer D. 2
Correct answer B. The method must assign it before returning; the caller need not initialise it
Correct answer B. The argument is passed by reference but cannot be modified by the method
Correct answer B. 0
Correct answer D. They must come after all required parameters and have compile-time constant defaults
Correct answer C. Show(b: 2, a: 1)
Correct answer C. int Get(int x) and string Get(int x)
Correct answer B. const is fixed at compile time; readonly can be assigned at declaration or in a constructor
Correct answer D. An InvalidOperationException is thrown
Correct answer B. double to int
Correct answer A. 2
Correct answer B. Converting a value type to object or an interface type, which copies it into a heap object
Correct answer A. An InvalidCastException is thrown
Correct answer C. abc in small letters
Correct answer B. The type is inferred at compile time and the variable stays strongly typed
Correct answer B. dynamic defers member binding and type checking to run time, while var is resolved at compile time
Correct answer A. 532
Correct answer B. 3
Correct answer B. -1
Correct answer D. 12