C# int Keyword with Example

In this tutorial, we will learn about the int keyword in C# (with Example), what is int keyword, how to use it in C#? By IncludeHelp Last updated : April 04, 2023

C# int Keyword

In C#, int is a keyword which is used to declare a variable that can store an integral type of value (signed integer) the range of -2,147,483,648 to 2,147,483,647. int keyword is an alias of System.Int32.

It occupies 4 bytes (32 bits) space in the memory.


int variable_name = value;

Example of int keyword in C#

Here, we are declaring an int variable num, initializing it with the value 12345 and printing its value, type, and size of an int type variable.

using System;
using System.Text;

namespace Test {
  class Program {
    static void Main(string[] args) {
      //variable declaration
      int num = 12345;

      //printing value
      Console.WriteLine("num: " + num);
      //printing type of variable
      Console.WriteLine("Type of num: " + num.GetType());
      //printing size
      Console.WriteLine("Size of a int variable: " + sizeof(int));
      //printing minimum & maximum value of int
      Console.WriteLine("Min value of int: " + int.MinValue);
      Console.WriteLine("Max value of int: " + int.MaxValue);

      //hit ENTER to exit


num: 12345
Type of num: System.Int32
Size of a int variable: 4
Min value of int: -2147483648
Max value of int: 2147483647

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.