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();
}
}
}