Friday, 17 August 2018

C#: Maximum and Minimum values of data types

Every data type has properties MinValue and MaxValue to get the minimum and maximum values.

Program.cs
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("byte: Min Value : {0}, Max Value : {1}", byte.MinValue, byte.MaxValue);
        Console.WriteLine("sbyte: Min Value : {0}, Max Value : {1}", sbyte.MinValue, sbyte.MaxValue);
        Console.WriteLine("int: Min Value : {0}, Max Value : {1}", int.MinValue, int.MaxValue);
        Console.WriteLine("uint: Min Value : {0}, Max Value : {1}", uint.MinValue, uint.MaxValue);
        Console.WriteLine("short: Min Value : {0}, Max Value : {1}", short.MinValue, short.MaxValue);
        Console.WriteLine("ushort: Min Value : {0}, Max Value : {1}", ushort.MinValue, ushort.MaxValue);
        Console.WriteLine("long: Min Value : {0}, Max Value : {1}", long.MinValue, long.MaxValue);
        Console.WriteLine("ulong: Min Value : {0}, Max Value : {1}", ulong.MinValue, ulong.MaxValue);
        Console.WriteLine("float: Min Value : {0}, Max Value : {1}", float.MinValue, float.MaxValue);
        Console.WriteLine("double: Min Value : {0}, Max Value : {1}", double.MinValue, double.MaxValue);
        Console.WriteLine("decimal: Min Value : {0}, Max Value : {1}", decimal.MinValue, decimal.MaxValue);
        Console.WriteLine("char: Min Value : {0}, Max Value : {1}", char.MinValue, char.MaxValue);
    }
}

Output

Previous                                                 Next                                                 Home

No comments:

Post a Comment