c#-7.0

What is the difference between “x is null” and “x == null”?

允我心安 提交于 2019-11-26 07:57:17
问题 In C# 7 we can use if (x is null) return; instead of if (x == null) return; Are there any advantages to using the new way (former example) over the old way? Are the semantics any different? Is just a matter of taste? If not, when should I use one over the other? Reference: What’s New in C# 7.0. 回答1: Update: The Roslyn compiler has been updated to make the behavior of the two operators the same when there is no overloaded equality operator . Please see the code in the current compiler results

What's the difference between System.ValueTuple and System.Tuple?

回眸只為那壹抹淺笑 提交于 2019-11-26 06:59:28
问题 I decompiled some C# 7 libraries and saw ValueTuple generics being used. What are ValueTuples and why not Tuple instead? https://docs.microsoft.com/en-gb/dotnet/api/system.tuple https://docs.microsoft.com/en-gb/dotnet/api/system.valuetuple 回答1: What are ValueTuples and why not Tuple instead? A ValueTuple is a struct which reflects a tuple, same as the original System.Tuple class. The main difference between Tuple and ValueTuple are: System.ValueTuple is a value type (struct), while System

Local function vs Lambda C# 7.0

我与影子孤独终老i 提交于 2019-11-26 06:58:41
问题 I am looking at the new implementations in C# 7.0 and I find it interesting that they have implemented local functions but I cannot imagine a scenario where a local function would be preferred over a lambda expression, and what is the difference between the two. I do understand that lambdas are anonymous functions meanwhile local functions are not, but I can\'t figure out a real world scenario, where local function has advantages over lambda expressions Any example would be much appreciated.

Enabling c# 7 in a asp.net application

梦想与她 提交于 2019-11-26 02:21:38
问题 I just started working on my old solution in Visual Studio 2017. Just opening the solution in the old IDE worked seamlessly. The c# application projects now default to the c# 7.0 compiler. The property pages of those project (compilation/advanced) let easily chose the targeted language version of the compiler, defaulting to the latest. I cannot find a way to enable c# 7.0 in the asp.net web projects though. If I write a statement such as: if (int.TryParse(\"1\", out int myInt)) { ... } the