c#-6.0

Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater

戏子无情 提交于 2019-11-27 21:19:28
问题 There is a similar question to this here but I believe that involves a different cause. I moved a class from a newer project into an older project. Both were targeting .net 4.6 however after the move I received the following error on build. Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater. I tried setting my project to build with C# 6 in the properties window with no change. 回答1: I eventually found the place to change it. It seems sometimes

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

与世无争的帅哥 提交于 2019-11-27 20:39:37
问题 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

How to convert array to dictionary

試著忘記壹切 提交于 2019-11-27 19:37:16
问题 How to convert below fieldList array to dictionary as Dictionary<string,column> (i.e. Dictionary of name property of column class as key and value property of dictionary as column object) . public class columninfo { public string name {get;set;} public column[] fieldList {get;set;} } public class column { public string name {get;set;} public string fieldname {get;set} public string format {get;set;} } 回答1: You can use a linq lambda for this. column[] columns = getColumninfo(); columns

How do you use verbatim strings with interpolation?

跟風遠走 提交于 2019-11-27 19:12:25
In C#6 there is a new feature: interpolated strings. These let you put expressions directly into code, rather than relying on indexes: string s = string.Format("Adding \"{0}\" and {1} to foobar.", x, this.Y()); Becomes: string s = $"Adding \"{x}\" and {this.Y()} to foobar."; However, we have a lot of strings across multiple lines using verbatim strings (mainly SQL statements) like this: string s = string.Format(@"Result... Adding ""{0}"" and {1} to foobar: {2}", x, this.Y(), x.GetLog()); Reverting these to regular strings seems messy: string s = "Result...\r\n" + $"Adding \"{x}\" and {this.Y()

How to use C# 6 with Web Site project type?

♀尐吖头ヾ 提交于 2019-11-27 17:33:36
Updated an existing Web Site project type Visual Studio 2015, I changed the Framework to 4.6. I then expected to have all those new features available in my code behind files. Unfortunately I'm getting errors like: Error CS8026: Feature 'expression-bodied property' is not available in C# 5. Please use language version 6 or greater. or e.g.: Error CS8026: Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater. I did a quick Google check and found a guy posting some comments in a blog posting of ScottGu (search for "8026" on the page). Since I do not

How to change language version in Visual Studio 2015

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 17:16:51
问题 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. 回答1: Try this.. Project -> Properties -> Build -> Advanced -> Language Version 回答2: Go to Project → Properties → Build → Advanced → Language Version → OK as shown with detail steps and screen

How do I disable C# 6 Support in Visual Studio 2015?

笑着哭i 提交于 2019-11-27 17:08:44
Background We have a project that we're developing in VS 2015 with C#6 enabled that occasionally needs to be opened by developers using VS 2013 without C#6. We have no intention to use C# 6 within this particular solution (as much as I'd like to). Problem Visual Studio and ReSharper suggest helpful C# 6 language constructs that render the solution inoperable in earlier versions of Visual Studio without C#6 support. I've disabled the ReSharper C#6 support but I can't seem to disable / limit C# features across the whole solution. Question How do I limit C# to C#5 capabilities within a solution

Formatting a string into columns using String Interpolation

旧巷老猫 提交于 2019-11-27 16:17:40
I need to print doubles so that definite number of symbols (like 8) is allocated for string representation of value. Next words should start at same index from beginning of string in each string. Now I have: value: 0 test value: 0.3333333333333 test value: 0.5 test I need: value: 0 test value: 0.33333333 test value: 0.5 test Test code: double[] ar = new double[] { 0, (double)1 / 3, (double)1 / 2 }; string s = "test"; foreach (var d in ar) { Console.WriteLine($"value: {d} {s}"); } What should I add after {d: ? You can use Alignment Component for this purpose. Like this: Console.WriteLine($

C#6's Improved overload resolution - clarification?

穿精又带淫゛_ 提交于 2019-11-27 15:47:18
问题 Among all the new features in C#6, the most mysterious feature (to me) is the "improved overload resolution" . Maybe it's because I couldn't find related info/examples/explanation about it. The only two remaining features not discussed are support for defining a custom Add extension method to help with collection initializers, and some minor but improved overload resolution Looking at the roslyn wiki There are a number of small improvements to overload resolution, which will likely result in

Null-conditional operator and string interpolation in C# 6

独自空忆成欢 提交于 2019-11-27 14:38:42
问题 Do the null-conditional operator and interpolated strings syntax resolve to just syntactic sugar? The null-conditional operator ( ?. ), which allows code clean-up through reducing "excessive" null checking, and interpolated strings ( ("\{X}, \{Y}") ), which brings the arguments and format into one, are new features in C# 6. Do these get compiled to their undesirable counterparts (i.e. the ugly code we sought to avoid)? I apologize for the naïve question, I don't have the best understanding of