UInt32.MinValue Field in C# with Examples


The UInt32.MinValue field in C# represents the minimum value of the 32-bit unsigned integer.

Syntax

Following is the syntax −

public const uint MinValue = 0;

Example

Let us now see an example to implement the UInt32.MinValue field −

using System;
public class Demo {
   public static void Main(){
      uint val1 = 23;
      uint val2 = 0;
      Console.WriteLine("Value1 = "+val1);
      Console.WriteLine("Value2 = "+val2);
      Console.WriteLine("HashCode for value1 = "+val1.GetHashCode());
      Console.WriteLine("HashCode for value2 = "+val2.GetHashCode());
      Console.WriteLine("Are they equal? = "+(val1.Equals(val2)));
      TypeCode type1 = val1.GetTypeCode();
      TypeCode type2 = val2.GetTypeCode();
      Console.WriteLine("TypeCode for val1 = "+type1);
      Console.WriteLine("TypeCode for val2 = "+type2);
      Console.WriteLine("Minimum Value = "+ UInt32.MinValue);
   }
}

Output

This will produce the following output −

Value1 = 23
Value2 = 0
HashCode for value1 = 23
HashCode for value2 = 0
Are they equal? = False
TypeCode for val1 = UInt32
TypeCode for val2 = UInt32
Minimum Value = 0

Example

Let us now see another example to implement the UInt32.MaxValue method −

using System;
public class Demo {
   public static void Main(){
      ulong[]val = {8998, 899898778, 878787878};
      uint res;
      foreach(ulong a in val){
         if(a >= UInt32.MinValue && a <= UInt32.MaxValue){
            res = Convert.ToUInt32(a);
            Console.WriteLine("Converted: "+res);
         } else {
            Console.WriteLine("Not Possible");
         }
      }
   }
}

Output

This will produce the following output −

Converted: 8998
Converted: 899898778
Converted: 878787878
raja
Published on 08-Nov-2019 06:58:24
Advertisements