3 ms·
Not quite equivalent, since System.Tuple is immutable. So, at minimum: public class Complex { private readonly double _i; private readonly double _j
by douche 10y ago
Not quite equivalent, since System.Tuple is immutable. So, at minimum:
public class Complex {
private readonly double _i;
private readonly double _j;
public double I {get {return _i;}}
public double J {get{return _j;}}
public Complex(double i, double j){
_i = i;
_j = j;
}
}
But System.Tuple is also IComparable, IStructuralComparable, IStructuralEquatable. I haven't had enough coffee yet to add all the boilerplate for that to the above, which only reinforces the point about verbosity.
- algorithmsRcool 10y agoAlthough with c# 6.0 (current release) you can simplify that to: public class Complex { public double I { get; } public double J { get; } public Complex(double i, double j) { I = i; J = j; } }
- doodpants 10y agoEven before C# 6.0, you could simplify it this way: public class Complex { public double I { get; private set; } public double J { get; private set; } public Complex(double i, double j) { I = i; J = j; } }