int calculation

In this chapter you will learn:

  1. integers and arithmetic operators
  2. Prefix and Postfix Increment Operators

integers and arithmetic operators

class MainClass// j a v a 2 s  .com
{

  public static void Main()
  {
    
    System.Console.WriteLine("10 / 3 = " + 10 / 3);
    System.Console.WriteLine("10 % 3 = " + 10 % 3);
    int intValue1 = 10;
    int intValue2 = 3;
    System.Console.WriteLine("intValue1 / intValue2 = " + intValue1 / intValue2);
    System.Console.WriteLine("intValue1 % intValue2 = " + intValue1 % intValue2);

  }
}

The code above generates the following result.

Prefix and Postfix Increment Operators

class Main// j  a v a  2  s  .c o m
{
  public static void Main()
  {
      int x;

      x = 1;
      System.Console.WriteLine("{0}, {1}, {2}", x++, x++, x);
      System.Console.WriteLine("{0}, {1}, {2}", ++x, ++x, x);
  }
}

Next chapter...

What you will learn in the next chapter:

  1. Integral type overflow
  2. Catch OverflowException Exception
Home » C# Tutorial » Byte, Integer, Long
Integer Family
Integer ranges
byte
Convert to byte
Parse string to byte
byte format
byte octal and hexadecimal
byte binary operation
byte overflow with unchecked
int
int value
Compare int value
int calculation
int value overflow
int binary operation
Parse string to int value
Format int value
int in binary, octal and hexadecimal
long
long value calculation
ulong