Introduction to Data Types in C# Language

Rumman Ansari   Software Engineer   2019-03-05   5641 Share
☰ Table of Contents

Table of Content:


Integer

Integer data types are used to work with numbers. In this case, the numbers are whole numbers like 10, 20 or 30. In C#, the datatype is denoted by the Int32 keyword. Below is an example of how this datatype can be used. In our example, we will define an Int32 variable called num. We will then assign an Integer value to the variable and then display it accordingly.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
 { 
  static void Main(string[] args) 
  {
   Int32 num=30;
   Console.Write(num);  
   
   Console.ReadKey();
  }
 }
}

Code Explanation:-

  1. The Int32 data type is specified to declare an Integer variable called num. The variable is then assigned a value of 30.
  2. Finally the console.write function is used to display the number to the console.

If the above code is entered properly and the program is executed successfully, following output will be displayed.

Output:

30

From the output, you can clearly see that the Integer variable called num was displayed in the console