-1
DateTime[] s = new DateTime { "2000:1:1", "2001:1:1", "2002:1:1", "2003:1:1" };
DateTime[] e = new DateTime { "2000:2:1", "2001:2:1", "2002:2:1", "2003:2:1" };

无法System.DateTime使用集合初始化程序初始化类型,因为它没有实现System.Collections.IEnumerable

4

4 回答 4

2

您将 astring放入 a DateTime[],只需将DateTime结构放入 a DateTime[]

  DateTime[] s = new DateTime[] { new DateTime(2000,1,1), new DateTime(2000,1,1), new DateTime(2000,1,1), new DateTime(2000,1,1) };
于 2013-11-04T09:34:50.353 回答
2

您不能将字符串隐式转换为 DateTime 对象。而且您在 . 之后缺少双方括号new DateTime

你应该做:

DateTime[] s = new DateTime[] { new DateTime(2000,1,1), new DateTime(2001,1,1), ....}
于 2013-11-04T09:34:56.530 回答
0

你可以这样写:

DateTime[] s = { new DateTime(2000, 1, 1), new DateTime(2001, 1, 1), new DateTime(2002, 1, 1), new DateTime(2003, 1, 1) };
于 2013-11-04T09:36:21.377 回答
0

工作正常...尝试:

DateTime[] e = { new DateTime(), DateTime.Now, DateTime.Now.AddHours(3)};
于 2013-11-04T09:34:43.313 回答