Fragrance
|
C# 7 finally introduced a feature called "Pattern" matching. C# language introduced the notion of a pattern that can be used in is-expression and inside a case block of a switch statement. With C# 7 three distinct matching formats are now possible.
First format is the normal one which we always use and had been there right from the first release of C#.
New pattern matching enables matching based on a specific class or structure. Inline with the expression you can even include the new variable instance which can be accessed within the next code block
Now the third format is the most interesting one i.e. var patterns. It uses the var keyword, and simply copies the source test variable or expression into a new, named variable
Above code is not useful unless you include the "when" clause, which is also new to C# 7.
With new C# 7 switch statement has become more powerful and a goto option for flow control processing with expression.
​Hope you liked the post and do share it. Happy Coding!!!
Comments
|
Categories
All
Archives
May 2020
|