views:

58

answers:

1

I was thinking to use Tuple class to store 2 integer information (StartAddress, EndAddress) I need in my program.

But I discover that Tuple items are ReadOnly, so if I need to set a value for an item, I need to re-instantiate a Tuple.

What is the reason behind this design decision?

+2  A: 

Tuples originated in functional programming. In (purely) functional programming, everything is immutable by design - a certain variable only has a single definition at all times, as in mathematics. The .NET designers wisely followed the same principle when integrating the functional style into C#/.NET, despite it ultimately being an OO (hybrid?) language.

Note: Though I suspect the fact that tuples are immutable doesn't really make your task much harder, there are also anonymous types (or perhaps just a simple struct) you might want to use.

Noldorin
It's the CLR designers, not the C# designers. System.Tuple in .NET 4 are also implicitly used by F#.
Julien Lebosquain
It was more the BCL developers than the C# designers - there was a decision, now that F# was joining the stable of .Net languages to have a unified Tuple type.
Damien_The_Unbeliever
Ahh the inevitable pedant. Also, F# used its own tuple types before .NET 4.0 - it's kind of irrelevant anyway.
Noldorin
Also, while we're being picky, Damien is correct - it was the .NET Framework (BCL) designers, not the CLR designers - the CLR can support mutable tuples if you wish to design such classes!
Noldorin