I am trying to implement tuples c# 7 new feature in Visual Studio Code in macOS.
using System;
using System.Collections.Generic;
namespace newcsharp
{
public class Program
{
public static void Main(string[] args)
{
int[] numbers = { 1, 3, 4, 10, 6, 20, 78, 15, 6 };
var result = Range(numbers);
Console.ReadLine();
}
private static (int Max, int Min) Range(IEnumerable<int> numbers)
{
int min = int.MaxValue;
int max = int.MinValue;
foreach (var n in numbers)
{
min = (n < min) ? n : min;
max = (n > max) ? n : max;
}
return (max, min);
}
}
}
I am getting the following erros.
I included System.ValueTuple package for using tuples feature in my project.
My project.json
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
},
"System.ValueTuple": "4.3.0"
},
"frameworks": {
"netcoreapp1.1": {
"imports": "dnxcore50"
}
},
"tooling": {
"defaultNamespace": "newcsharp"
}
}
any help appreciated.
C# 7 features such as tuples now work natively with the latest version of VSCode and the C# extension.
Note that you do need to reference System.ValueTuple.
Just make sure to use .csproj instead of project.json.
You can use the following minimal .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="*"/>
</ItemGroup>
</Project>
Enjoy ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With