我要说的是,我正在制造一个名称和日期都相同的一类物体。 在确定日期时哪些是最佳做法?
var employees = new List<Employee>()
{
new Employee {Name = "Foo", HireDate = new DateTime(2000, 1, 15)},
new Employee {Name = "Bar", HireDate = new DateTime(2001, 5, 25)},
};
或
var employees = new List<Employee>()
{
new Employee {Name = "Foo", HireDate = DateTime.Parse("2000, 1, 15")},
new Employee {Name = "Bar", HireDate = DateTime.Parse("2001, 5, 25")},
};
I am assuming there really isn t a huge difference, but I am slightly new to C# so I am not sure which is prefered by the maj或ity of C# programmers and why (perf或mance, readability, etc.). Thanks in advance f或 any insight you can give!