nedcomp hosting homepage

Producten en Diensten
Dedicated servers
Datacenter informatie
Partners, resellers
Helpdesk informatie
Technische docs, tools
Support homepage
ASP componenten
Praktische ASP, ASP.NET
Visual route server
Whois (domein gegevens)
Software documentatie
Whitepapers
Zoeken
Nedcomp / algemeen

Zoeken
 

Copyright © Nedcomp Hosting
Telefoon nr :   +31 184 670111
Fax nummer :   +31 184 631384
E-mailadres :   info@nedcomp.nl
 

C# Programmer's Reference  

% Operator

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

expr1 % expr2

Where:

expr1
An expression.
expr2
An expression.

Remarks

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

Example

// cs_operator_modulus.cs
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.6
0.6
-1.2

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

See Also

C# Operators | 7.7.3 Remainder operator