introductory-examples/simple-types/ex3.cs - Demonstrations of numeric types in C#. | Lecture 2 - slide 7 : 43 Program 3 |
using System; using System.Globalization; class NumberDemo{ public static void Main(){ sbyte sb1 = sbyte.MinValue; // Signed 8 bit integer System.SByte sb2 = System.SByte.MaxValue; Console.WriteLine("sbyte: {0} : {1}", sb1, sb2); byte b1 = byte.MinValue; // Unsigned 8 bit integer System.Byte b2 = System.Byte.MaxValue; Console.WriteLine("byte: {0} : {1}", b1, b2); short s1 = short.MinValue; // Signed 16 bit integer System.Int16 s2 = System.Int16.MaxValue; Console.WriteLine("short: {0} : {1}", s1, s2); ushort us1 = ushort.MinValue; // Unsigned 16 bit integer System.UInt16 us2= System.UInt16.MaxValue; Console.WriteLine("ushort: {0} : {1}", us1, us2); int i1 = int.MinValue; // Signed 32 bit integer System.Int32 i2 = System.Int32.MaxValue; Console.WriteLine("int: {0} : {1}", i1, i2); uint ui1 = uint.MinValue; // Unsigned 32 bit integer System.UInt32 ui2= System.UInt32.MaxValue; Console.WriteLine("uint: {0} : {1}", ui1, ui2); long l1 = long.MinValue; // Signed 64 bit integer System.Int64 l2 = System.Int64.MaxValue; Console.WriteLine("long: {0} : {1}", l1, l2); ulong ul1 = ulong.MinValue; // Unsigned 64 bit integer System.UInt64 ul2= System.UInt64.MaxValue; Console.WriteLine("ulong: {0} : {1}", ul1, ul2); float f1 = float.MinValue; // 32 bit floating-point System.Single f2= System.Single.MaxValue; Console.WriteLine("float: {0} : {1}", f1, f2); double d1 = double.MinValue; // 64 bit floating-point System.Double d2= System.Double.MaxValue; Console.WriteLine("double: {0} : {1}", d1, d2); decimal dm1 = decimal.MinValue; // 128 bit fixed-point System.Decimal dm2= System.Decimal.MaxValue; Console.WriteLine("decimal: {0} : {1}", dm1, dm2); string s = sb1.ToString(), t = 123.ToString(); } }