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
)
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.
Tuple types are immutable. Data members of System. ValueTuple types are fields.
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.
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.
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; } } }
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