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
0 answers

How do I extract ValueTuple data with NpgsqlDataReader

I'm using NpgsqlDataReader to extract data from a PostgreSQL database in C#. My PostgreSQL table has a column of the cidr data type. In C# when I use the NpgsqlDataReader's .GetFieldType(index).ToString(); method, I get the…
JacquesB
  • 37
  • 5
0
votes
4 answers

Access members of nullable ValueTuple?

To access ValueTuple members, I would do public Plane Init (ValueTuple vertices) { Vector4D[] m_vertices = new Vector4D [4]; m_vertices[0] = vertices.Item1; // etc return this; } Can I use a…
Razzupaltuff
  • 2,250
  • 2
  • 21
  • 37
0
votes
1 answer

CLI/C++ named ValueTuple like in C# (.Net Framework 4.7)

Is there any way to achieve the same in CLI/C++ as the following: namespace Test { static class TestClass { static (int a, int b) test = (1, 0); static void v() { var a = test.a; var b = test.b; _ = (a, b); } } } So is there any…
NexCastus
  • 23
  • 1
0
votes
0 answers

Tuple vs ValueTuple mutability

Why is Tuple immutable, and ValueTuple mutable? ValueTuple valTup = new ValueTuple("a", "b"); valTup.Item1 = "c"; // OK Tuple tup = new Tuple("a", "b"); tup.Item1 = "c"; // Doesn't…
Yahav
  • 25
  • 1
0
votes
1 answer

Convert an array of separated strings into an ValueTuple list

I have an array of strings separated by ; , like this myArr[0]="string1;string2;string3" myArr[1]="string4;string5;string6" how can i convert it into an list of ValueTuple(string,string,string)? List<(string,string,string)>
L4marr
  • 291
  • 2
  • 16
0
votes
3 answers

declare value tuples in generic method signature

I want to create methods which are able to convert lists to tuples (or a struct) by matching types. I would also need to create overloads for several tuple component counts so I could for example call: var t1 =…
codymanix
  • 28,510
  • 21
  • 92
  • 151
0
votes
0 answers

How to use ValueTuple with a single item?

In an ASP.NET Core 5 MVC application, I have this call: var result = ctx.ExecQuery<(string Item1)>("select '' as Item1"); This throws 5 compile-time errors starting at Invalid expression term 'string' The following works: var result =…
Andrus
  • 26,339
  • 60
  • 204
  • 378
0
votes
0 answers

C# How an I set a ValueTuple field value by its name

Can I set a ValueTuple field value only by have its name as string ? I guess I can do this using Reflection but is there more direct way to do it ? I want to do something like this : (string email, int age) user = ("abcd@domain.com", 20) …
AnGG
  • 679
  • 3
  • 9
0
votes
2 answers

Casting value of Dictionary to an tuple fails

I have a dictionary with a key of a known type (in the given example: string) and a tuple as value. I want to pass this dictionary around in the application and usually can unpack the data easily by using the key of the dictionary (in the real…
codefluent
  • 125
  • 1
  • 11
0
votes
0 answers

How to convert a collection into a value tuple?

The purpose is to create a valueTuple dynamically from a collection. In this collection, values might be different Type. The created ValueTuple would have the same value type. IList tupleElements = new List(); …
Ethan
  • 11
  • 1
0
votes
2 answers

Tuple lambda syntax suddenly not working in C#

I'm using .NET Framework 4.7, I have implemented several of syntax like this Task<(bool isSuccess, string message)> DownloadFileResource() And it already worked by getting there result with var var downloadResult = await…
Tấn Nguyên
  • 1,607
  • 4
  • 15
  • 25
0
votes
0 answers

JQuery serialization to Value Tuple

I am trying to submit a form with JQuery to C#, using a Value Tuple as one of the properties of the target object. However, it doesn't seem to work; which I am guessing has something to do with how Value Tuples are constructed, as you also get…
v07
  • 11
  • 3
0
votes
3 answers

Property in a new instance of class and previously created instance of same class are referenced same memory

// Interface public interface IItem { Collection Collection { get; set; } } public class Collection : BindableObject { public static readonly BindableProperty ItemsProperty = BindableProperty.Create("Items",…
0
votes
1 answer

Base type of ValueTuple

Can't figure out with next comparing: var type = typeof(ValueTuple); if (type.BaseType == typeof(ValueTuple)) // returns 'false', however, 'type.BaseType' is 'System.ValueTuple' at runtime Who can to explain that?
anatol
  • 1,680
  • 2
  • 24
  • 47
0
votes
3 answers

valuetuple doesn't work for one of my 4.7.2 projects

I have multiple projects in the solution, all targeting 4.7.2. I then add a method in a lib project that returns valueTuple. Multiple projects call this method, all projects are fine(compiled) except one project. This one project generates compiler…
Ken
  • 21
  • 4