Re:Microfeatures I'd like to see in more languages
by KMag on Friday January 06, 2023 @12:44AM
(#34271436)
C#'s % is explicitly the remainder operator, not the modulo operator.
[ Parent
| on HN ]
Re:Microfeatures I'd like to see in more languages
by recursive on Friday January 06, 2023 @01:02AM
(#34271535)
Not according to reflection.
Expression<Func<int, int>> lambda = n => n % 2;
Console.WriteLine(((dynamic)lambda).Body.NodeType);
Output is "Modulo".
Re:Microfeatures I'd like to see in more languages
by KMag on Friday January 06, 2023 @08:00AM
(#34274153)
Hmm... I haven't read the official spec, just the Microsoft documentation: 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.