我在新的C#7中看到了var模式的这个例子
if (o is var x) Console.WriteLine($"it's a var pattern with the type {x?.GetType()?.Name}");
Run Code Online (Sandbox Code Playgroud)
只是使用有什么不同:
var x = o;
Console.WriteLine($"it's a var pattern with the type {x?.GetType()?.Name}");
Run Code Online (Sandbox Code Playgroud)
当这种模式是一个有用的解决方案.