c#-6.0

How can I add C# 6.0 to Visual Studio 2013? [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-11-29 09:24:29
This question already has an answer here: How to enable C# 6.0 feature in Visual Studio 2013? 6 answers Is there any way to add C# 6.0 to Visual Studio 2013? If I can't why is that? The best you can currently do for VS2013 is download the April End User Preview , which is pretty outdated by now. The VS2013 compiler (as is) doesn't "understand" C#-6 features. Most, if not all of the C# new features are syntactic sugar which the compiler interprets and emits different code for. In order for VS2013 to support that, it has to upgrade the compiler to support those features. Not to mention VS2015

Roslyn and .NET Runtime version [duplicate]

若如初见. 提交于 2019-11-29 09:08:59
This question already has an answer here: Does C# 6.0 work for .NET 4.0? 5 answers Is it possible to use Roslyn compiler and new features of C# 6.0 with old versions of .NET Runtime (for example, .NET 4.0)? For example, I want use the expression-bodied members ( int S => x + y; instead of int S { get { return x + y; } } ) in .NET 4.0 application. The new C# 6.0 features don't depend upon framework support so yes, you an app compiled with the C# 6.0 compiler will run on .NET 4.0, assuming of course you specify you are targeting .NET 4.0 in your project file in the first place. As of now Roslyn

nameof with Generics

我只是一个虾纸丫 提交于 2019-11-29 05:27:50
I was experimenting with nameof with generics. I didn't get the result I was expecting. I'm not sure if this is part of the spec or not. class MainClass { public static void Main (string[] args) { Console.WriteLine ($"Hello { nameof(FooBar<string>)! }"); } } class FooBar<T> { } The output I get is Hello FooBar! I would expect some details about the type parameters. I tried it with a method and that fails with a compiler error: class MainClass { public static void Main (string[] args) { Console.WriteLine ($"Hello { nameof(Do<string>) }"); } public static T Do<T>() {} } Error CS8084: An argument

C# 6 how to format double using interpolated string?

谁说我不能喝 提交于 2019-11-29 04:21:25
问题 I have used some new features of C# 6 incl. interpolated string for simple usage (showing message which contains string variables like $"{EmployeeName}, {Department}"). Now I want to use interpolated string for showing formatted double value. Example var aNumberAsString = aDoubleValue.ToString("0.####"); How can I write it as interpolated string? something like $"{aDoubleValue} ...." 回答1: You can specify a format string after an expression with a colon ( : ): var aNumberAsString = $"

How to change language version in Visual Studio 2015

纵然是瞬间 提交于 2019-11-29 03:01:38
I want to use the nameof operator in my C# project in Visual Studio 2015 but the compiler complains with the following message. Feature 'nameof operator' is not available in C# 5. Please use language version 6 or greater. I want to know how I can change the C# language version from Visual Studio 2015. Try this.. Project -> Properties -> Build -> Advanced -> Language Version Go to Project → Properties → Build → Advanced → Language Version → OK as shown with detail steps and screen shots below: Follow these steps to change the language version of your project 1: Open your project with Visual

null conditional operator not working with nullable types?

五迷三道 提交于 2019-11-29 00:49:42
I'm writing a piece of code in c#6 and for some strange reason this works var value = objectThatMayBeNull?.property; but this doesn't: int value = nullableInt?.Value; By not works I mean I get a compile error saying Cannot resolve symbol 'Value' . Any idea why the null conditional operator ?. isn't working? Okay, I have done some thinking and testing. This is what happens: int value = nullableInt?.Value; Gives this error message when compiling: Type 'int' does not contain a definition for `Value' That means that ? 'converts' the int? into the actual int value. This is effectively the same as:

ReSharper: setting C# language level for Solution

我只是一个虾纸丫 提交于 2019-11-28 23:53:29
问题 Further to this question, I have lots of projects inside a solution and I dont want to create a dotsettings file for each project. Can anyone help me set the C# Language Level on a solution level. This is relevant for me as I downloaded VS2015 today and ReSharper is offering me useful refactor suggestions based on targeting C# 6 and my projects are using C#5. 回答1: I added below settings in .sln.DotSettings <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/

TryParse with out var param

試著忘記壹切 提交于 2019-11-28 20:59:08
A new feature in C# 6.0 allows to declare variable inside TryParse method. I have some code: string s = "Hello"; if (int.TryParse(s, out var result)) { } But I receive compile errors: What I am doing wrong? P.S.: in project settings C# 6.0 and .NET framework 4.6 are set. A new feature in C# 6.0 allows to declare variable inside TryParse method. Declaration expressions was cut from C# 6.0 and wasn't shipped in the final release. You currently can't do that. There is a proposal for it on GitHub for C# 7 (also see this for future reference). Update (07/03/2017) With the official release of C#7,

Why has a lambda with no capture changed from a static in C# 5 to an instance method in C# 6?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 20:12:42
This code throws an exception on the marked line: using System; using System.Linq.Expressions; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { Action<int, int> a = (x, y) => Console.WriteLine(x + y); ParameterExpression p1 = Expression.Parameter(typeof(int), "p1"); ParameterExpression p2 = Expression.Parameter(typeof(int), "p2"); // Here is the exception ArgumentNullException. MethodCallExpression call = Expression.Call(a.Method, p1, p2); } } } Now, I've tested this code in VS2013 (works like a charm) and in VS2015 Community (throws the exception). I followed

Error CS1056: Unexpected character '$' running the msbuild on a tfs continuous integration process

£可爱£侵袭症+ 提交于 2019-11-28 18:40:09
I have a project that the framework is targeting .NET Framework 4.6.1 , as part of the continuous integration process on the tfs we created a Build Solution task to ensure that the code compiles correctly. Now the TFS server has the latest version of the .Net Famework 4.6.2 . On the register this is the value for the Release key of the framework On all other OS versions: 394806 => .NET Framework 4.6.2 But when the build runs it comes with this error: Error CS1056: Unexpected character '$' I don't want to replace the string interpolation with the string.Format to solve this issue, please