What's the benefit of var patterns in C#7?
问题 I don't understand the use case of var patterns in C#7. MSDN: A pattern match with the var pattern always succeeds. Its syntax is expr is var varname where the value of expr is always assigned to a local variable named varname . varname is a static variable of the same type as expr . The example on MSDN is pretty useless in my opinion, especially because the if is redundant: object[] items = { new Book("The Tempest"), new Person("John") }; foreach (var item in items) { if (item is var obj)