Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C#
C# Reference
C# Operators
 / Operator

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
C# Language Reference
/ Operator (C# Reference)

The division operator (/) divides its first operand by its second. All numeric types have predefined division operators.

User-defined types can overload the / operator (see operator). An overload of the / operator implicitly overloads the /= operator.

When you divide two integers, the result is always an integer. For example, the result of 5 / 2 is 2. To determine the remainder of 5 / 2, use the modulo operator (%). To obtain a quotient as a rational number or fraction, give the dividend or divisor type float or type double. You can do this implicitly by putting a decimal point after the number, as shown in the following example.

C#
class Division
{
    static void Main()
    {
        Console.WriteLine(5 / 2);
        Console.WriteLine(5 % 2);

        Console.WriteLine(5 / 2.1);
        Console.WriteLine(5.1 / 2);
        Console.WriteLine(-5 / 2);
    }
}
/*
Output:
2
1
2.38095238095238
2.55
-2
*/

Concepts

Reference

Other Resources

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker