C# uint Keyword with Example

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

C# uint Keyword

In C#, uint is a keyword which is used to declare a variable that can store an integral type of value (unsigned integer) the range of 0 to 4,294,967,295. uint keyword is an alias of System.UInt32.

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

Syntax

uint variable_name = value;

Example of uint keyword in C#

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

using System;
using System.Text;

namespace Test {
  class Program {
    static void Main(string[] args) {
      //variable declaration
      uint 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 uint variable: " + sizeof(uint));
      //printing minimum & maximum value of uint
      Console.WriteLine("Min value of uint: " + uint.MinValue);
      Console.WriteLine("Max value of uint: " + uint.MaxValue);

      //hit ENTER to exit
      Console.ReadLine();
    }
  }
}

Output

num: 12345
Type of num: System.UInt32
Size of a uint variable: 4
Min value of uint: 0
Max value of uint: 4294967295




Comments and Discussions!

Load comments ↻






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