c#-6.0

Asp.net MVC Razor view - CS1525: Invalid expression term '.'

六月ゝ 毕业季﹏ 提交于 2020-01-11 04:47:05
问题 I have two identical ASP.Net 4.6 MVC project, project 1 is using roslyn complier within the site which is working fine. c:\windows\system32\inetsrv>C:\Websites1\bin\roslyn\csc.exe Microsoft (R) Visual C# Compiler version 1.2.0.60325 With the second project I'm getting the error below, it's using the complier from .Net framework. c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" Microsoft (R) Visual C# Compiler version 4.6.1590.0 Line 6: @if (!Model?.Item?

What is the => assignment in C# in a property signature

懵懂的女人 提交于 2020-01-08 08:47:47
问题 I came across some code that said public int MaxHealth => Memory[Address].IsValid ? Memory[Address].Read<int>(Offs.Life.MaxHp) : 0; Now I am somewhat familiar with Lambda expressions. I just have not seen it used it this way. What would be the difference between the above statement and public int MaxHealth = x ? y:z; 回答1: What you're looking at is an expression-bodied member not a lambda expression. When the compiler encounters an expression-bodied property member, it essentially converts it

What is the => assignment in C# in a property signature

こ雲淡風輕ζ 提交于 2020-01-08 08:47:01
问题 I came across some code that said public int MaxHealth => Memory[Address].IsValid ? Memory[Address].Read<int>(Offs.Life.MaxHp) : 0; Now I am somewhat familiar with Lambda expressions. I just have not seen it used it this way. What would be the difference between the above statement and public int MaxHealth = x ? y:z; 回答1: What you're looking at is an expression-bodied member not a lambda expression. When the compiler encounters an expression-bodied property member, it essentially converts it

Null Conditional Operator, not behaving as expected on some machines

谁说胖子不能爱 提交于 2020-01-04 07:36:20
问题 I have the following code in a DelegatingHandler for a WebApi 2 project. protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var content = await request.Content?.ReadAsStringAsync(); _log.Information("Received {request} with content body: {content}.", request, content); // Run the rest of the request pipeline. var result = await base.SendAsync(request, cancellationToken); var responseContent = await result.Content?

Why is throwing an exception inside lambda a C# 7 feature? [duplicate]

£可爱£侵袭症+ 提交于 2020-01-04 05:22:18
问题 This question already has answers here : Why can't I throw exceptions from an expression-bodied member? (5 answers) Closed 2 years ago . This statement doesn't compile in VS2015, but does in VS2017: var example = new Action( () => throw new Exception() What had to change in the way labmdas are parsed in order to support throwing an exception inside a labmda expression? Especially because if I use a lambda body, VS2015 is perfectly happy: My question is similar to Why can't I throw exceptions

New C# 6.0 String Interpolation statements don't compile [duplicate]

女生的网名这么多〃 提交于 2020-01-03 13:37:43
问题 This question already has answers here : What is the final format for string interpolation in VS 2015? (2 answers) Closed 4 years ago . I am trying to implement some of the features in this video but I'm not having much luck with the new String Interpolation syntax (I have everything else working, at least that's in this code). I am using Visual Studio 2015 CTP6, I have configured it to use .NET 4.6 and have gone into the Build options to make sure I was specifying C# 6.0. I have also

New C# 6.0 String Interpolation statements don't compile [duplicate]

百般思念 提交于 2020-01-03 13:37:10
问题 This question already has answers here : What is the final format for string interpolation in VS 2015? (2 answers) Closed 4 years ago . I am trying to implement some of the features in this video but I'm not having much luck with the new String Interpolation syntax (I have everything else working, at least that's in this code). I am using Visual Studio 2015 CTP6, I have configured it to use .NET 4.6 and have gone into the Build options to make sure I was specifying C# 6.0. I have also

Enums in lambda expressions are compiled differently; consequence of overload resolution improvements?

牧云@^-^@ 提交于 2019-12-31 08:32:12
问题 While trying out the Visual Studio 2015 RC, I received a run-time error on previously working code. Given the lambda (x => x.CustomerStatusID == CustomerStatuses.Active) which was passed to a function as an Expression<> , the debugger shows a difference in the expression tree. Formerly it compiled as this: .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 } But in C# 6.0 it now compiles

Enums in lambda expressions are compiled differently; consequence of overload resolution improvements?

删除回忆录丶 提交于 2019-12-31 08:31:54
问题 While trying out the Visual Studio 2015 RC, I received a run-time error on previously working code. Given the lambda (x => x.CustomerStatusID == CustomerStatuses.Active) which was passed to a function as an Expression<> , the debugger shows a difference in the expression tree. Formerly it compiled as this: .Lambda #Lambda1<System.Func`2[Services.DataClasses.CustomerDC,System.Boolean]>(Services.DataClasses.CustomerDC $x) { (System.Int32)$x.CustomerStatusID == 0 } But in C# 6.0 it now compiles

What is meant by “the null conditional operator short circuits”?

只谈情不闲聊 提交于 2019-12-31 05:15:31
问题 Note to future visitors: This question was based on faulty repro code. The ?. operator does indeed short circuit. You can close this browser tab now. There are many sources on the web that claim that the null conditional operator ( ?. ) short circuits (e.g. http://www.informit.com/articles/article.aspx?p=2421572, search for "circuit"). I cannot detect any such thing: static void Main() { var c = new C(); Console.WriteLine(c?.Inner?.Inner); //does not rely on short circuiting, works Console