Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a version of the class Tuple whose Items properties are not readonly and can be set? [duplicate]

Tags:

c#

.net

tuples

I want to know whether there is a built-in version of the class Tuple whose Items properties are not readonly and can be set.

Or can someone provide me such a version?

I am searching for a solution that implements the base functions of the Tuple class, (Equals, GetHashCode)

like image 295
GianT971 Avatar asked Oct 16 '11 23:10

GianT971


People also ask

Is tuple read-only?

The properties in a Tuple are all read-only, i.e., they cannot be changed once they ahve been created. The size of the Tuple is fixed since it cannot be changed once it has been defined at the time when the Tuple is created.

Are tuples immutable in C#?

Tuple types are immutable. Data members of System. ValueTuple types are fields.

Why are tuples immutable in C#?

One thing that makes tuples distinct is that they are immutable. That means you can't change them at all once they have been created. Any properties in that tuple are going to be read-only. It also means that the size of the tuple is fixed after you create it.

What is AC tuple?

The Tuple<T> class was introduced in . NET Framework 4.0. A tuple is a data structure that contains a sequence of elements of different data types. It can be used where you want to have a data structure to hold an object with properties, but you don't want to create a separate type for it.


1 Answers

No, as mentioned a Tuple<> is intended to be immutable.

I use a custom Pair class if I need a mutable type that does the same thing, although in the spirit of embracing function concepts, I try not to use it.

namespace StackOverflow.Helpers {     public class Pair<T1, T2>     {         public T1 First { get; set; }         public T2 Second { get; set; }     } }  
like image 89
Ritch Melton Avatar answered Sep 24 '22 19:09

Ritch Melton