NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

% Operator

The modulus operator (%) computes the remainder after dividing its first operand by its second. All numeric types have predefined modulus operators.

User-defined types can overload the % operator (see operator).

Example

using System;
class Test {
   public static void Main() {
      Console.WriteLine(5 % 2);      // int
      Console.WriteLine(-5 % 2);      // int
      Console.WriteLine(5.0 % 2.2);   // double
      Console.WriteLine(5.0m % 2.2m);// decimal
      Console.WriteLine(-5.2 % 2.0);   // double
   }
}

Output

1
-1
0.59999999999999964
0.6
-1.2000000000000002

Note the round-off errors associated with the double type.

See Also

C# Operators | CLR 7.7.3 Remainder operator