New language feature: Switch Operator (?::)

In this chapter, we will design a new C# langauge feature that we call Switch operator (?::). This feature is derived from two existing C# language constructs: switch statement (https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/switch) and conditional operator (?:) (https://docs.microsoft.com/en-us/cpp/cpp/conditional-operator-q). It allows writing conditional expressions that can switch on multiple values of the expression and return a corresponding value or a default value. For example, consider the following switch statement that computes a string representation for an integral expression:

public string GetString(int expression){ string expressionStr; switch (expression) ...

Get Roslyn Cookbook 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.