I'm wondering if there's an operator to simplify this? Similar to the += operator.
if (x > val) x = val;
x "new operator" val;
//date times
DateTime d1 = dsi_curr.cycleSteps.StepsUpTimestamp[0] ;
DateTime d2 = dsi_curr.cycleSteps.StepsUpTimestamp[dsi_curr.cycleSteps.StepsUpTimestamp.Length-1];
if (d1 < curbt.details.StartDate) {
curbt.details.StartDate = d1;
}
if (d2 > curbt.details.EndDate) {
curbt.details.EndDate = d2;
}
There is no builtin operator for this, but you can add your own method to simplify this:
static void MakeLesserOf(ref DateTime self, DateTime other) {
self = self > other ? other : self;
}
static void MakeGreaterOf(ref DateTime self, DateTime other) {
self = self < other ? other : self;
}
Now you can rewrite your code as follows:
MakeLesserOf(curbt.details.StartDate, d1);
MakeGreaterOf(curbt.details.EndDate, d2);
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