Tuples are good for expressing integer values. But he has a penalty for readability, "Item1" and "Item2" are not so intuitive. To improve on the latter, I introduced a class alias as shown below. I was wondering if anyone has a better solution. One way or another, a "dedicated" class is still needed. The example below is naive, it simply indicates a problem.
enum Unit { Celsius, Fahrenheit }
class Temperature: Tuple<decimal, Unit>
{
public decimal Value
{
get { return Item1; }
}
public Unit
{
get { return Item2; }
}
public Temperature(decimal item1, Unit item2)
: base(item1, item2)
{
}
}
var temp = new Temperature(37, Unit.Celsius);
temp.Item1 == temp.Value == 37;
temp.Item2 == temp.Unit == Unit.Celsius;
source
share