Vision document for H1 2018
Dukc
ajieskola at gmail.com
Fri Mar 16 20:31:42 UTC 2018
On Friday, 16 March 2018 at 18:35:14 UTC, Tony wrote:
>
> I thought C# was like Java and does not allow free procedures.
> Can you give an example of C# procedural-style IO?
Well, this is not IO, but:
public struct DivInt
{ public int quot;
public int rem;
}
public static class Utility
{ public static DivInt Div(this int dividee, int divisor)
{ int quot;
int rem;
quot = Math.DivRem(dividee, divisor, out rem);
//always round down
if(rem < 0)
{ quot--;
rem += divisor;
}
return new DivInt{quot = quot, rem = rem};
}
}
Could be used in some way like:
int quotient;
int remainder;
if (true)
{ var divResult = (x + y).Div(ASlowFunction());
quotient = divResult.quot;
remainder = divResult.rem;
}
If you say it sucks that one has to declare an utility class just
to be nominally object-oriented, I agree.
More information about the Digitalmars-d-announce
mailing list