Questions tagged [valuetuple]

This covers the ValueTuple struct used by C#'s tuples

Value tuples are tuple types introduced in the .NET Framework 4.7 to provide the runtime implementation of tuples in C#. They are different from tuple classes, like Tuple<T1>, because they are value types, rather then reference ones.

141 questions
2
votes
3 answers

Is params Keyword supports with ValueTuple as a parameter C# 7.0?

I search in StackOverflow, don't find any articles or anything related to that. For example, the following example describes array of ValueTuple (string CategoryName, params string[] Properties)[] MyArrayValueTupleParameter // Compile-Time Syntax…
deveton
  • 291
  • 4
  • 26
2
votes
2 answers

Can you declare item names in a ValueTuple value in a Dictionary?

Is it possible to declare a ValueTuple as a value in a Dictionary, and include names for the items in the ValueTuple? I've tried: var x = new Dictionary = {...} but I didn't really expect that to work,…
Michael Ray Lovett
  • 6,668
  • 7
  • 27
  • 36
2
votes
1 answer

How does grouping data with parentheses work?

I recently came across this: (int, string) tst = (0, "Test"); The idea behind it seems amazing, before whenever I wanted to map two variables I would use a KeyValuePair. It seems that this is available in .NET Core and not on the regular .NET…
Roiw
  • 147
  • 2
  • 16
2
votes
1 answer

Could not load file or assembly System.ValueTuple Version=4.0.3.0

I am getting the following runtime exception, except I think my case is different than the dozen or so I've seen so far, most of which are a couple years old. Could not load file or assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral,…
grinder22
  • 551
  • 4
  • 17
2
votes
1 answer

Can ValueTuples be used with .net 4.5.2?

I have an MVC 5 project that targets .net framework 4.52 and I installed the System.ValueTuple through Nuget. I'm using Visual Studio 2017 on Windows 7. During development, Visual Studio doesnt complain about the Tuple return type but when I build I…
Necromancer
  • 390
  • 5
  • 15
2
votes
0 answers

Weird behaviour when deconstructing covariant interfaces into ValueTuples with extension methods

This is my covariant interface with one method returning and enumerable which is also covariant (as it always is). Simple. public interface IDataSource { IAsyncEnumerable StreamData(CancellationToken cancellationToken =…
Bruno Zell
  • 7,761
  • 5
  • 38
  • 46
2
votes
1 answer

Problem with ValueTuple in Azure Function (v1)

I am currently experiencing a problem in one of my Azure Functions. I want to use a library that makes use of ValueTuple. The lib is built against .net Core 2.0. This leads to the following error message in my function: Reference to type…
Jörg A.
  • 21
  • 1
2
votes
2 answers

Deconstruct Container containing ValueTuple in LINQ

I am able to deconstruct a container via an extension method: var limits = new[] { MyEnum.A , MyEnum.B , MyEnum.C } .ToDictionary( x => x , x => ( SupportedLimit: GetLimit( x ) , RequiredLimit: 0 ) ); public static…
nonsensation
  • 3,627
  • 6
  • 28
  • 41
2
votes
3 answers

Check individual items from a list of Valuetuple in c# 7

Please consider the following list of ValueTuple C#7 List<(double prices, int matches)> myList = new List<(double, int)>(); myList.Add((100, 9)); myList.Add((100.50 , 12)); I can do Foreach var i in…
Roblogic
  • 107
  • 3
  • 8
2
votes
1 answer

Can I return a generic type inside of a ValueTuple?

Here's some code for an example. I get the error "Cannot implicitly convert type 'string' to 'T'" public ValueTuple TestMethod() { return ("test", ""); } How would I go about doing this? Is this outside of the limitations of…
Tom F
  • 807
  • 6
  • 20
2
votes
2 answers

Value tuple type pattern

I am trying to use a type pattern in C# 7 against a tuple type: var lst = new List(); lst.Add("foo"); lst.Add(("bar","baz")); foreach (var item in lst) { switch (item) { case string s: break; case (string,…
Zev Spitz
  • 13,950
  • 6
  • 64
  • 136
2
votes
2 answers

Can tuple literals in C# 7.0 enable aspect oriented programming

I'm referring to tuple literals as described here: https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/#comment-321926 Love the tuple literal idea. However I foresee a lot of looking up the order of the items in return tuples…
2
votes
3 answers

ValueTuple: what is wrong with creation of octuple?

ValueTuple as a new feature in C# 7.0 is having public method Create which helps to create ValueTuples (from singleton to octuple or more) on the other hand we can also use new to achieve the same results. I noticed these behave differently. I am…
Gaurav Arora
  • 2,243
  • 6
  • 40
  • 57
1
vote
3 answers

Modifying list of ValueTuples vs list of integers

Having trouble wrapping my head around the concept of modifying these two different lists. So when using a regular for loop to iterate over each one, we can directly modify the list of integers, but cannot modify a specific item in the list of…
William
  • 429
  • 3
  • 5
  • 16
1
vote
0 answers

Can I define a shorthand for tuples in C#

The following function takes an object as a parameter, the object is actually a tuple and is cast as such: private void MyFunction(object clientWithThreadIDAsObject) { (TcpClient m_sender, int m_nListenerThreadID) clientWithThreadID =…
gnitsuk
  • 31
  • 3