CSharp - Write program to Define int type variable


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.


The data type for numeric values is called int.

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

numbers are entered without quotes.


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);