CSharp - Write program to Define int type variable

Requirements

Store numbers rather than text.

  • You will create (declare) a variable called number.
  • Afterward, you will store some number in it.
  • Finally, you will display the variable's value to the user.

Hint

The data type for numeric values is called int.

This is the data type for whole numbers (integers).

numbers are entered without quotes.

Demo

using System;

class Program/* w ww .j  av  a 2  s .  co  m*/
{
    static void Main(string[] args)
    {
        // Variable for storing number (with initial value) 
        int number = -12;

        // Output of value of the variable 
        Console.WriteLine("Value of the variable: " + number);


        // Precalculation of result (into a variable) 
        int sum = 1 + 1;

        // Output to the user 
        Console.WriteLine("One and one is: " + sum);
    }
}

Result