I am not sure how to use new C# 7 features in existing solution. I tried using pattern matching in a switch statement but I keep getting Value of integral type expected
error.
Is there a trick to enable it? I though I can just use new features if I open the solution in VS 2017.
My projects are targeting .net 4.6.2.
Here is the sample code
private void CS7Test(object o)
{
switch (o)
{
case null:
Console.WriteLine("it's a constant pattern");
break;
case int i:
Console.WriteLine("it's an int");
break;
case UserInfo p when p.Username.StartsWith("Ka"):
Console.WriteLine($"a Ka person {p.Username}");
break;
case UserInfo p:
Console.WriteLine($"any other person {p.Username}");
break;
case var x:
Console.WriteLine($"it's a var pattern with the type {x?.GetType().Name} ");
break;
default:
break;
}
}