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
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
您将 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) };
您不能将字符串隐式转换为 DateTime 对象。而且您在 . 之后缺少双方括号new DateTime
。
你应该做:
DateTime[] s = new DateTime[] { new DateTime(2000,1,1), new DateTime(2001,1,1), ....}
你可以这样写:
DateTime[] s = { new DateTime(2000, 1, 1), new DateTime(2001, 1, 1), new DateTime(2002, 1, 1), new DateTime(2003, 1, 1) };
工作正常...尝试:
DateTime[] e = { new DateTime(), DateTime.Now, DateTime.Now.AddHours(3)};