基本數據類型操做

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Ex03._04
{
    class Program
    {
        static void Main(string[] args)
        {
            objectFunctionality();
            dataTypeFunctionality();
            charFunctionality();
            parseFromString();
            userDatesAndTimes();
            userBigInteger();
            Console.ReadKey();
        }
        static void objectFunctionality()
        {
            Console.WriteLine("類型繼承測試:");
            Int32 intValue = 12;
            Console.WriteLine("{0}.GetHashCode()={1}", intValue, intValue.GetHashCode());
            Console.WriteLine("{0}.Equals(23)={1}", intValue, intValue.Equals(23));
            Console.WriteLine("{0}.ToString()={1}", intValue, intValue.ToString());
            Console.WriteLine("{0}.GetType()={1}", intValue, intValue.GetType());
            Console.WriteLine("{0}.GetTypeCode()={1}", intValue, intValue.GetTypeCode());
            Console.WriteLine();
            Console.Beep();
        }
        static void dataTypeFunctionality()
        {
            Console.WriteLine("數據類型展現:");
            Console.WriteLine("Max of Int32:{0}", Int32.MaxValue);
            Console.WriteLine("Min of Int32:{0}", Int32.MinValue);
            Console.WriteLine("Max of Double:{0}", Double.MaxValue);
            Console.WriteLine("Min of Double:{0}", Double.MinValue);
            Console.WriteLine("Double.PositiveInfinity:{0}", Double.PositiveInfinity);
            Console.WriteLine("Double.NegativeInfinity:{0}", Double.NegativeInfinity);
            Console.WriteLine("Boolean.FalseString()={0}", Boolean.FalseString);
            Console.WriteLine("Boolean.TrueString()={0}", Boolean.TrueString);
            Console.WriteLine();
            Console.Beep();
        }
        static void charFunctionality()
        {
            Console.WriteLine("Char類型功能展現:");
            Char myChar = 'a';
            Console.WriteLine("Char.IsDigit('{0}'):{1}", myChar, Char.IsDigit(myChar));
            Console.WriteLine("Char.IsLetter('{0}'):{1}", myChar, Char.IsLetter(myChar));
            Console.WriteLine("Char.IsLetterOrDigit('{0}'):{1}", myChar, Char.IsLetterOrDigit(myChar));
            Console.WriteLine("Char.IsWhiteSpace('Hello World!',5):{0}", Char.IsWhiteSpace("Hello World!", 5));
            Console.WriteLine("Char.IsWhiteSpace('Hello World!',6):{0}", Char.IsWhiteSpace("Hello World!", 6));
            Console.WriteLine("Char.IsPunctuation('?'):{0}", Char.IsPunctuation('?'));
            Console.WriteLine();
            Console.Beep();
        }
        static void parseFromString()
        {
            Console.WriteLine("從字符串解析數據:");
            Boolean b = Boolean.Parse("True");
            Console.WriteLine("Value of b:{0}", b);
            Double d = Double.Parse("99.98");
            Console.WriteLine("Value of d:{0}", d);
            Int32 i = Int32.Parse("63");
            Console.WriteLine("Value of i:{0}", i);
            Char c = Char.Parse("w");
            Console.WriteLine("Value of c:{0}", c);
            Console.WriteLine();
            Console.Beep();
        }
        static void userDatesAndTimes()
        {
            Console.WriteLine("使用System.DateTime和System.TimeSpan");
            //構造日期,年月日
            DateTime dt = new DateTime(2012, 9, 14);
            Console.WriteLine("這是{0}月的第{1}天", dt.Month, dt.Day);
            Console.WriteLine("目前的日期:{0}", dt.ToShortDateString());
            //增長2個月
            dt = dt.AddMonths(4);
            Console.WriteLine("增長2個月以後的日期:{0}", dt.ToShortDateString());
            Console.WriteLine("目前是夏令時嗎?:{0}", dt.IsDaylightSavingTime());
            //構造時間,時分秒
            TimeSpan ts = new TimeSpan(13, 25, 0);
            Console.WriteLine(ts);
            //減去15分鐘
            Console.WriteLine("減去15分鐘:{0}", ts.Subtract(new TimeSpan(0, 15, 0)));
            Console.Beep();
            Console.WriteLine();
        }

        static void userBigInteger()
        {
            Console.WriteLine("使用大數BigInteger:");
            BigInteger biggy = BigInteger.Parse("999999999999999999999999999999999999999999999999999999999");
            Console.WriteLine("這是一個大數嗎?{0}", biggy);
            //是否是偶數
            Console.WriteLine("Is this an even value?{0}", biggy.IsEven);
            //是2的冪嗎
            Console.WriteLine("Is this a power of two?{0}", biggy.IsPowerOfTwo);
            BigInteger reallyBig = BigInteger.Multiply(biggy, BigInteger.Parse("8888888888888888888888888888888888"));
            Console.WriteLine("這但是個夠大的數:{0}", reallyBig);
            Console.Beep();
            Console.WriteLine();
        }
    }
}
相關文章
相關標籤/搜索