C# int (Integer)

The int data type in C# is used to store whole numbers, both positive and negative, without decimal points. It is one of the most commonly used types for representing integers in a range from -2,147,483,648 to 2,147,483,647.

Key Concepts

  • The int type is a 32-bit signed integer.
  • It is used for counting and basic calculations where no decimal precision is required.
  • Examples include counting items, looping, and arithmetic operations.

Example of Using an int

Code Example

// Declare an integer variable
int myNumber = 100;

// Output the integer to the console
Console.WriteLine(myNumber);

Output:

100

Code Explanation: The int variable myNumber is initialized with the value 100. It is printed using the Console.WriteLine() method, which outputs the integer value.

Output Explanation: The integer 100 is displayed because it was assigned to the variable myNumber and output to the console.