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
0
votes
1 answer

Does ValueTuple is a bad choice if there are too many "fields" due to its value type nature?

Since I decided to diversify myself with Rust and Go I became overly concerned about copying / reference / moving etc. And recently I really wondered if ValueTuple also suffer from the typical caveat of struct that is that its size should not be…
Natalie Perret
  • 8,013
  • 12
  • 66
  • 129
0
votes
0 answers

Why can't I use Marshal.SizeOf() to calculate the size of an instance of type ValueTuple?

Why does the following code: ValueTuple origin = (0.0, 0.0); Console.WriteLine($"Size of ValueTuple: {Marshal.SizeOf(origin)}"); throw System.ArgumentException: 'Type …
mikevg
  • 53
  • 4
0
votes
1 answer

Selecting Tuples from ILookup throws exception

I have an ILookup which is supposed to store display information for elements (that otherwise only exist as enums in the application) in a dropdown. The Tuples are accessed like this: public IEnumerable<(int,…
0
votes
1 answer

Why do I need to cast methods to `Action` or `Func` to use it in value tuples?

Why the compiler can't handle these x3 and x4 assignments? void X() { (Func, int) x1 = (GetX, 1); // OK object x2 = x1; // OK object x3 = (GetX, 1); …
lmcarreiro
  • 5,312
  • 7
  • 36
  • 63
0
votes
1 answer

ValueTuple<(string loanID, decimal x, ...)> does not contain a definition for 'loanID' in c#

I am just passing a ValueTuple to a function. I want to process the Values within this ValueTuple. Unfortunately, VS 2017 only allows me to access credit.Item1. No further Items. So far I had no issues with ValueTuples. The error in the compiler…
julian bechtold
  • 1,875
  • 2
  • 19
  • 49
0
votes
1 answer

Default values for attributes contained within value tuples

Is it possible to define an optional or default attribute within a value tuple? for example in the below value tuple the Func type = null will be optional: public static void MustMatch(params (Func prop, Func
Farhad-Taran
  • 6,282
  • 15
  • 67
  • 121
0
votes
1 answer

Check items from a List of ValueTuple and return results in another List of ValueTuple C#7

Please consider the following list of ValueTuple C#7 static void Main(string[] args) { List<(double prices, int matches)> myList = new List<(double, int)>(); myList.Add((100, 10)); myList.Add((100.50 , 12)); …
Roblogic
  • 107
  • 3
  • 8
0
votes
0 answers

What does "Version" mean when viewing reference properties in Visual Studio?

I am currently battling "DLL hell" in Visual Studio 2017. For unknown reasons, I suddenly got a problem with System.ValueTuple, where the error I get is the classic problem that have been asked many times before: Could not load file or assembly…
Ted
  • 19,727
  • 35
  • 96
  • 154
0
votes
1 answer

Using ValueTuple while compiling a class from text runtime

I'm trying to compile a class from text at runtime. My problem is that my class uses a valueTupe in a function (AllLines), and I receive an error "C:\xxxx.cs(19,28): error CS0570: 'BaseClass.AllLines' is not supported by the language" when using…
WynDiesel
  • 1,104
  • 7
  • 38
0
votes
3 answers

How can you loop over lists of tuples where you compare the tuple in one list to the other tuples in the same list?

for x in check: this = sorted(x) #the first tuple for y in check: that = sorted(y) #the other tuples in the list? in order to compare with 'this'. if this == that: check.remove(x) …
Anna
  • 23
  • 3
0
votes
1 answer

generic reference equality comparer does not work for ValueTuple

I have written a generic equality comparer that should always compare by reference, no matter how the GetHashCode and Equals methods of the parameter type look like: public class ReferenceEqualityComparer : IEqualityComparer { public…
Kjara
  • 2,504
  • 15
  • 42
0
votes
1 answer

VS 2017 intellisense issue with ValueTuple

Visual Studio 2017 Pro in Windows 7 with .net framework 4.7 developer kit installed and without System.ValueTuple nuget. Intellisense provides the correct tuple name in the suggestion list, but when chosen, writes the old tuple name (Item1, Item2,…
Endy Tjahjono
  • 24,120
  • 23
  • 83
  • 123
0
votes
0 answers

It appears that value tuples are breaking the SonarC# code analyzer

I am trying to use the new ValueTuple language feature. While it works fine in the build and test, when SonarC# attempts to analyze the code I get the following error: ERROR: Error during SonarQube Scanner execution …
anthonyterra
  • 171
  • 1
  • 3
0
votes
1 answer

ValueTuple in ASP.NET Core MVC

It seems like Razor doesn't understand the ValueTuple. In my Razor page: @{ var x = (1, "a"); } The code above gives me: An error occurred during the compilation of a resource required to process this request. Please review the following…
kazinix
  • 28,987
  • 33
  • 107
  • 157
-1
votes
1 answer

How can I get the compiler aliases of ValueTuple field names for reflection

ValueTuples allow for compiler aliases for their public fields (Item1, Item2, etc...). For example: var tuple = (Name:"apple",Date:DateTime.Now); var nameFieldValue = tuple.Name;//"apple" //here tuple.Name is a compiler alias for…
Nigel
  • 2,961
  • 1
  • 14
  • 32
1 2 3
9
10