c#-7.0

Which C# version .NET Core uses?

拈花ヽ惹草 提交于 2019-12-04 22:30:52
I know that C# version depends on .NET Framework . But .NET Core which version uses? Particularly .NET Core 2? C#7? .NET Core 2.0 references Roslyn 2.3, which corresponds to Visual Studio 2017 version 15.3 and supports C# 7.1. The C# what's new version history page gives a list of all versions plus their associated Visual Studio and .NET core version: C# 7.3 Visual Studio 2017 version 15.7, and in the .NET Core 2.1 SDK 2.1.300 RC1 C# 7.2 Visual Studio 2017 version 15.5, and in the .NET Core 2.0 SDK. C# 7.1 Visual Studio 2017 version 15.3, and in the .NET Core 2.0 SDK. C# 7.0 Visual Studio 2017

Convert anonymous type to new C# 7 tuple type

放肆的年华 提交于 2019-12-04 22:17:01
The new version of C# is there, with the useful new feature Tuple Types: public IQueryable<T> Query<T>(); public (int id, string name) GetSomeInfo() { var obj = Query<SomeType>() .Select(o => new { id = o.Id, name = o.Name, }) .First(); return (id: obj.id, name: obj.name); } Is there a way to convert my anonymous type object obj to the tuple that I want to return without mapping property by property (assuming that the names of the properties match)? The context is in a ORM, my SomeType object has a lot of other properties and it is mapped to a table with lot of columns. I wanna do a query that

Tuple syntax in VS 2017

。_饼干妹妹 提交于 2019-12-04 09:58:51
问题 In VS2017 RC, when you tried to use new tuple syntax, you received the following error: CS8179 Predefined type 'System.ValueTuple`X' is not defined or imported In order to use tuple syntax, you had to manually import ValueTuple nuget package into the project. Not a big deal, as it was pre-release version and I thought it will be changed in RTM so it will be enabled by default. Unfortunately in the final release version it is still the case and you have to download nuget package for every

An expression tree may not contain a reference to a local function

痴心易碎 提交于 2019-12-04 03:51:13
Error: An expression tree may not contain a reference to a local function public void Initialize() { CloudStorageProperties ImageFileProperties(string fileName) => _cloudStorage.GetBlob(CloudStorageType.Image, fileName).FileProperties; Config = new MapperConfiguration(x => { x.CreateMap<Category, CategoryViewModel>() .ForMember(vm => vm.ImagePath, m => m.MapFrom(src => ImageFileProperties(src.ImageFile.Name).Uri.AbsoluteUri)); }); } I can replace the local function with an anonymous function and it works but re sharper says that I should convert it to a local function. Why is this not allowed?

Why can I ref return an item of an array that only exists inside the method?

六眼飞鱼酱① 提交于 2019-12-04 03:27:21
I was trying out the new ref returns of C#7. I am able to compile and build this: public ref string MisUseRefReturn(int index) { string[] array = { "a", "b", "c", "d" }; return ref array[index]; //array[2] gets out of scope when this method returns! } According to MSDN: The return value cannot be a local variable in the method that returns it; it must have a scope that is outside the method that returns it. It can be an instance or static field of a class, or it can be an argument passed to the method. Attempting to return a local variable generates compiler error CS8168, "Cannot return local

Using “is” keyword with “null” keyword c# 7.0

落爺英雄遲暮 提交于 2019-12-04 01:01:42
问题 Recently i find out, that the following code compiles and works as expected in VS2017. But i can't find any topic/documentation on this. So i'm curious is it legit to use this syntax: class Program { static void Main(string[] args) { var o = new object(); Console.WriteLine(o is null); o = null; Console.WriteLine(o is null); Console.ReadLine(); } } BTW this is not working in VS2015 回答1: Yes, it's entirely valid. This uses the pattern matching feature of C# 7, which is available with is

Are C# anonymous types redundant in C# 7

北城以北 提交于 2019-12-04 00:56:02
Since C# 7 introduces value tuples, is there a meaningful scenario where they are better suited than tuples? For example, the following line collection.Select((x, i) => (x, i)).Where(y => arr[y.i].f(y.x)).ToArray(); makes the following line collection.Select((x, i) => new {x, i}).Where(y => arr[y.i].f(y.x)).ToArray(); redundant. What would be the use case where one is better used over the other (for either performance reasons or optimization)? Obviously, if there is a need for more than six fields, tuples cannot be used, but is there something a bit more nuanced to it? There are various

Why Local Functions generate IL different from Anonymous Methods and Lambda Expressions?

夙愿已清 提交于 2019-12-04 00:45:25
Why the C# 7 Compiler turns Local Functions into methods within the same class where their parent function is. While for Anonymous Methods (and Lambda Expressions) the compiler generates a nested class for each parent function, that will contain all of its Anonymous Methods as instance methods ? For example, C# code (Anonymous Method) : internal class AnonymousMethod_Example { public void MyFunc(string[] args) { var x = 5; Action act = delegate () { Console.WriteLine(x); }; act(); } } Will produce IL Code (Anonymous Method) similar to: .class private auto ansi beforefieldinit AnonymousMethod

Can we deploy a C# 7 web app to Azure using Kudu?

最后都变了- 提交于 2019-12-03 23:22:38
Since Visual Studio 2017 is released and we can use the new C# 7 features I expected this will work when deploying on Azure Web apps. Unfortunately we're seeing compile errors when using continuous deployment (kudu git deploy) so it seems Azure doesn't support the new toolchain yet. Is there anything we can do to get this to work now (besides publishing the assemblies directly)? since we don't yet have msbuild15 in Azure. if you want to use c#7 features with continuous integration, you may need some workaround for dotnet core web solution , you can build it in Azure out of the box . (it uses

Tuple syntax in VS 2017

女生的网名这么多〃 提交于 2019-12-03 04:31:47
In VS2017 RC, when you tried to use new tuple syntax, you received the following error: CS8179 Predefined type 'System.ValueTuple`X' is not defined or imported In order to use tuple syntax, you had to manually import ValueTuple nuget package into the project. Not a big deal, as it was pre-release version and I thought it will be changed in RTM so it will be enabled by default. Unfortunately in the final release version it is still the case and you have to download nuget package for every single project to use tuple syntax. Is there a way to have tuple syntax enabled for every project by