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
答案 0 :(得分:2)
您将string
放在DateTime[]
中,只需将DateTime
结构放在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) };
答案 1 :(得分:2)
您无法隐式将字符串转换为DateTime对象。你错过了new DateTime
之后的双方括号。
你应该这样做:
DateTime[] s = new DateTime[] { new DateTime(2000,1,1), new DateTime(2001,1,1), ....}
答案 2 :(得分:0)
工作正常...尝试:
DateTime[] e = { new DateTime(), DateTime.Now, DateTime.Now.AddHours(3)};
答案 3 :(得分:0)
你可以这样写:
DateTime[] s = { new DateTime(2000, 1, 1), new DateTime(2001, 1, 1), new DateTime(2002, 1, 1), new DateTime(2003, 1, 1) };