adsense

Friday, September 13, 2024

C # 8 More concise Switch

 In C# 8.0, the Switch statements has become more powerful with patterns. All the  cases have turned into expressions and become more readable. 

Following code illustrates basic usage of new switch.

var action= 1;


var result = operation switch

{

    1 => "Action 1",

    2 => "Action 2",

    3 => "Action 3",

    4 => "Action 4",

    _ => "No Action  performed"

};


Console.WriteLine(result );


More information can be found here.

Chaeers,

Samitha

No comments:

Post a Comment