Updated on Kisan Patel
In C# each data type has its own, unique maximum and minimum values that could be assigned to it. This technique allows the compiler to perform internal checking for validity.
The following example demonstrate how to determine minimum and maximum values of data types.
using System; namespace ConsoleApp { class Program { static void Main(string[] args) { Console.WriteLine("System Minimum\n"); Console.WriteLine("MinByte {0}", Byte.MinValue); Console.WriteLine("MinInt16 {0}", Int16.MinValue); Console.WriteLine("MinChar {0}", Char.MinValue); Console.WriteLine("MinDouble {0}", Double.MinValue); Console.WriteLine("MinDecimal {0}", Decimal.MinValue); Console.WriteLine("System Maximum\n"); Console.WriteLine("MaxByte {0}", Byte.MaxValue); Console.WriteLine("MaxInt16 {0}", Int16.MaxValue); Console.WriteLine("MaxChar {0}", Char.MaxValue); Console.WriteLine("MaxDouble {0}", Double.MaxValue); Console.WriteLine("MaxDecimal {0}", Decimal.MaxValue); Console.ReadKey(); } } }
In above C# program, we have used MinValue()
and MaxValue()
methods to display the minimum and maximum values of the various data types.
The output of the above C# program…