class Car
{
-Car()
{
// … …
}
}
public class Bus
{
protected static readonly DateTime globalStartTime;
protected int RouteNumber { get; set; }
static Bus() //静态构造函数
{
globalStartTime = DateTime.Now;
Console.WriteLine("Static ctor sets global start time to {0}", globalStartTime.ToLongTimeString());
}
public Bus(int routeNum)
{
RouteNumber = routeNum;
Console.WriteLine("{0} is created.", RouteNumber);
}
public void Drive()
{
TimeSpan elapsedTime = DateTime.Now - globalStartTime;
Console.WriteLine("{0} is starting its route {1:N2} minutes after global start time {2}.",
this.RouteNumber,
elapsedTime.TotalMilliseconds,
globalStartTime.ToShortTimeString());
}
}
class TestBus
{
static void Main()
{
Bus bus = new Bus(71);
bus.Drive();
System.Threading.Thread.Sleep(25);
Bus bus2 = new Bus(72);
bus2.Drive();
System.Console.WriteLine("Press any key to exit.");
System.Console.ReadKey();
}
}
/* Output:
Static ctor sets global start time to 10:04:08 AM
71 is created.
71 is starting its route 21.00 minutes after global start time 10:04 AM.
72 is created.
72 is starting its route 46.00 minutes after global start time 10:04 AM.
*/
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有