Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

/: practical reference

/: practical reference: / divides according to operand types; integral division truncates the fraction toward zero.

Version: C# language; verified against C# 14 reference

Syntax

left / right

/ divides according to operand types; integral division truncates the fraction toward zero.

Choose the intended numeric type and validate the divisor before using it.

7/2 differs from 7.0/2, and implicit numeric promotions may not be obvious.

Integer and decimal division by zero throws; floating point yields infinity or NaN.

The complete program actually uses /; its exact expected stdout is 3\n3.5.

Examples

using System;
using System.Linq;
using System.Threading.Tasks;

Console.WriteLine(7 / 2); Console.WriteLine(7.0 / 2);

Result

3
3.5

The complete program actually uses `/`; its exact expected stdout is `3\n3.5`.

Sources