1
我想创建一个模拟时间的类。这是我到目前为止。如何创建一个模拟时间的类?
namespace TimeSimulationConsole
{
class Program
{
static void Main(string[] args)
{
Time startTime = new Time();
startTime.Day = 1;
startTime.Month = 1;
startTime.Year = 2000;
DateTime gameDate = DateTime.Parse(startTime.Day, startTime.Month, startTime.Year);
Console.WriteLine(gameDate);
Console.ReadLine();
}
}
class Time
{
public int Day { get; set; }
public int Month { get; set; }
public int Year { get; set; }
}
}
我基本上想要定义一个开始时间,以便我稍后可以修改或添加几天。但现在我只想将其转换为DateTime并通过控制台显示。
我写的代码不起作用,看来我无法解析startTime。
['DateTime.Parse'](https://msdn.microsoft.com/en-us/library/system.datetime.parse.aspx)是用于从一个字符串解析日期时间。你想要的是[DateTime构造函数]之一(https://msdn.microsoft.com/en-us/library/xcfzdy4x.aspx)。 – Blorgbeard
谢谢。好的,我需要再读一遍。即使在观看微软课程后,其中一些内容仍然没有保留。所有这些提醒都非常复杂。 – Dennis