using System;
*// When 5 is divided by 3, the remainder is 2.*
Console.WriteLine(5 % 3);
*// When 1000 is divided by 90, the remainder is 10.*
Console.WriteLine(1000 % 90);
*// When 100 is divided by 90, the remainder is also 10.*
Console.WriteLine(100 % 90);
*// When 81 is divided by 80, the remainder is 1.*
Console.WriteLine(81 % 80);
*// When 1 is divided by 1, the remainder is zero.*
Console.WriteLine(1 % 1);2
10
10
1
0

for

if

Console.WriteLine

using System;
class Program
{
static void Main()
{
*//*
*// Prints every tenth number from 0 to 200.*
*// Includes the first iteration.*
*//*
for (int i = 0; i < 200; i++)
{
if ((i % 10) == 0)
{
Console.WriteLine(i);
}
}
}
}0
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190

DivideByZeroException

class Program
{
static void Main()
{
int zero = int.Parse(*"0"*);
int result = 100 % zero;
}
}Unhandled exception.
System.DivideByZeroException: Attempted to divide by zero.
at Program.Main()...

Add: 1 ns
Subtract: 1 ns
Multiply: 2.7 ns
Divide: 35.9 ns

List Every Nth

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Apr 27, 2023 (simplify).