4 ms·
C#'s % is explicitly the remainder operator, not the modulo operator.
by KMag 4y ago
C#'s % is explicitly the remainder operator, not the modulo operator.
- recursive 4y agoNot according to reflection. Expression<Func<int, int>> lambda = n => n % 2; Console.WriteLine(((dynamic)lambda).Body.NodeType); Output is "Modulo".
- KMag 4y agoHmm... I haven't read the official spec, just the Microsoft documentation: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/arithmetic-operators https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... In any case, the behavior is rem, not mod. Ada has both rem and mod operatiors. I'm not sure how many other languages have operators for both.
- cpurdy 4y agoEcstasy uses % for modulo, and /% for divrem (division and remainder). So "a = b % c" for calculating the modulo, but "(a, r) = b /% c" to get the divisor and remainder.