c#-7.0

Could not load file or assembly 'System.ValueTuple'

早过忘川 提交于 2019-11-27 02:07:30
问题 I've got a VS2017 project that compiles to a DLL which is then called by an EXE written by someone else. Both projects target .Net Framework 4.6.2. I rewrote one of my DLL methods to return a tuple and also imported the associated NuGet package. When I compile the project it includes System.ValueTuple.dll in the output directory which is then deployed to other machines where my DLL is loaded and called by the EXE. But when the EXE attempts to call the method that returns a tuple it crashes:

Does C# 7.0 work for .NET 4.5?

ぃ、小莉子 提交于 2019-11-27 01:47:26
I created a project in Visual Studio 2017 RC to check whether I can use new C# 7.0 language features in a .NET Framework 4.5 project. It seems to me that after referencing System.ValueTuple NuGet, new tuples are working fine. Is there anything else I should think about, or is this going to work? After checking System.ValueTuple NuGet dependencies, it looks like .NET Framework 4.0 is not supported. Is this the case, or is there some way to make the new language work in this runtime also? Let's go through the features new in C# 7.0 : Tuples: The System.ValueTuple package has a version for the

C#7: Underscore ( _ ) & Star ( * ) in Out variable

人走茶凉 提交于 2019-11-27 01:05:43
I was reading about new out variable features in C#7 here . I have two questions: It says We allow "discards" as out parameters as well, in the form of a _ , to let you ignore out parameters you don’t care about: p.GetCoordinates(out var x, out _); // I only care about x Q: I guess this is just an info and not a new feature of C#7 because we can do so in pre C#7.0 too: var _; if (Int.TryParse(str, out _)) ... or am I missing something here? My code gives an error when I do as mentioned in same blog: ~Person() => names.TryRemove(id, out *); * is not a valid identifier. An oversight by Mads

C# 7 .NET / CLR / Visual Studio version requirements

孤街醉人 提交于 2019-11-26 22:20:50
问题 What are the minimum .NET framework and CLR version requirements for running C# 7? Also, do I need VS 2017 to compile C# 7? 回答1: You do NOT need to target .NET 4.6 and above, that is incorrect. To use Tuples, you need the System.ValueTuple NuGet package. Right on https://www.nuget.org/packages/System.ValueTuple/ you can see it says it supports 4.5 and above, and actually, it supports 4.0 and above. And if you want to get crazy, if you create your own System.ValueTuple class that does exactly

Using a C# 7 tuple in an ASP.NET Core Web API Controller

倖福魔咒の 提交于 2019-11-26 21:47:38
问题 Do you know why this works: public struct UserNameAndPassword { public string username; public string password; } [HttpPost] public IActionResult Create([FromBody]UserNameAndPassword usernameAndPassword) { Console.WriteLine(usernameAndPassword); if (this.AuthenticationService.IsValidUserAndPasswordCombination(usernameAndPassword.username, usernameAndPassword.password)) return new ObjectResult(GenerateToken(usernameAndPassword.username)); return BadRequest(); } But when I replace it with a

Local function vs Lambda C# 7.0

时间秒杀一切 提交于 2019-11-26 21:23:12
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. Thanks. This was explained by Mads Torgersen in C# Design Meeting Notes where local functions were first

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

夙愿已清 提交于 2019-11-26 19:30:57
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 Yuval Itzchakov 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.Tuple is a reference type ( class ). This is meaningful when talking about allocations and GC

Predefined type 'System.ValueTuple´2´ is not defined or imported

≡放荡痞女 提交于 2019-11-26 14:21:40
I've installed Visual Studio 15 Preview 3 and tried to use the new tuple feature static void Main(string[] args) { var x = DoSomething(); Console.WriteLine(x.x); } static (int x, int y) DoSomething() { return (1, 2); } When I compile I get the error: Predefined type 'System.ValueTuple´2´ is not defined or imported According to the blog post , this features should be "on" by default. What did I do wrong? For .NET 4.6.2 or lower, .NET Core 1.x, and .NET Standard 1.x you need to install the NuGet package System.ValueTuple : Install-Package "System.ValueTuple" Or using a package reference in VS

Does C# 7.0 work for .NET 4.5?

三世轮回 提交于 2019-11-26 12:28:41
问题 I created a project in Visual Studio 2017 RC to check whether I can use new C# 7.0 language features in a .NET Framework 4.5 project. It seems to me that after referencing System.ValueTuple NuGet, new tuples are working fine. Is there anything else I should think about, or is this going to work? After checking System.ValueTuple NuGet dependencies, it looks like .NET Framework 4.0 is not supported. Is this the case, or is there some way to make the new language work in this runtime also? 回答1:

C#7: Underscore ( _ ) & Star ( * ) in Out variable

£可爱£侵袭症+ 提交于 2019-11-26 12:27:03
问题 I was reading about new out variable features in C#7 here. I have two questions: It says We allow \"discards\" as out parameters as well, in the form of a _ , to let you ignore out parameters you don’t care about: p.GetCoordinates(out var x, out _); // I only care about x Q: I guess this is just an info and not a new feature of C#7 because we can do so in pre C#7.0 too: var _; if (Int.TryParse(str, out _)) ... or am I missing something here? My code gives an error when I do as mentioned in