本例效果圖:
代碼:
using System; class MyClass { static void Main() { Console.WriteLine("sbyte 類型:"); sbyte sbyteVar = (sbyte.MaxValue + sbyte.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", sbyte.MinValue, sbyteVar, sbyte.MaxValue); Console.WriteLine("byte 類型:"); byte byteVar = (byte.MaxValue + byte.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", byte.MinValue, byteVar, byte.MaxValue); Console.WriteLine("short 類型:"); short shortVar = (short.MaxValue + short.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", short.MinValue, shortVar, short.MaxValue); Console.WriteLine("ushort 類型:"); ushort ushortVar = (ushort.MaxValue + ushort.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", ushort.MinValue, ushortVar, ushort.MaxValue); Console.WriteLine("int 類型:"); int intVar = (int.MaxValue + int.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", int.MinValue, intVar, int.MaxValue); Console.WriteLine("uint 類型:"); uint uintVar = (uint.MaxValue + uint.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", uint.MinValue, uintVar, uint.MaxValue); Console.WriteLine("long 類型:"); long longVar = (long.MaxValue + long.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", long.MinValue, longVar, long.MaxValue); Console.WriteLine("ulong 類型:"); ulong ulongVar = (ulong.MaxValue + ulong.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", ulong.MinValue, ulongVar, ulong.MaxValue); Console.WriteLine("float 類型:"); float floatVar = (float.MaxValue + float.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", float.MinValue, floatVar, float.MaxValue); Console.WriteLine("double 類型:"); double doubleVar = (double.MaxValue + double.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", double.MinValue, doubleVar, double.MaxValue); Console.WriteLine("decimal 類型:"); decimal decimalVar = (decimal.MaxValue + decimal.MinValue) / 2; Console.WriteLine("{0}、{1}、{2}\n", decimal.MinValue, decimalVar, decimal.MaxValue); Console.WriteLine("char 類型:"); char charVar = '萬'; Console.WriteLine("{0}、{1}\n", charVar, ++charVar); Console.WriteLine("bool 類型:"); bool boolVar = true; Console.WriteLine("{0}、{1}\n", boolVar, !boolVar); Console.WriteLine("string 類型:"); string stringVar = "萬一的 Delphi 博客"; Console.WriteLine("{0}、Length: {1}\n", stringVar, stringVar.Length); Console.ReadKey(); } }