2014-09-22 38 views
0

我试图用for循环打印日期列表。我收到一个错误,说'AddDays'不是'System.Array'的成员。如何打印日期列表asp.net

Dim payDates(10) as Date 

    For index As Integer = 1 to 10 
     Redim Preserve payDates(index) 
     payDates(index) = payDates.AddDays(1) 
     index +=1 
    NEXT 

    Response.Write(payDates) 
+0

如答案中所述,该数组不是日期或日期时间对象,因此如果不首先引用索引就不能使用AddDays。 但我相信你在错误的轨道上,ReDim可能不是想要的。 你可以发表你想要什么'Response.Write(payDates)'来显示的例子吗? – NiKiZe 2014-09-22 17:24:13

回答

2

我不是VB专家,但你需要访问数组的索引,而不是该数组本身:

Dim payDates(10) as Date 

    For index As Integer = 1 to 10 
     Redim Preserve payDates(index) 
     payDates(index) = payDates(index).AddDays(1) 
     index +=1 
    NEXT 

    Response.Write(payDates) 

你也migzht想写每次约会。在这种情况下,改变你的代码如下:

Dim payDates(10) as Date 

    For index As Integer = 1 to 10 
     Redim Preserve payDates(index) 
     payDates(index) = payDates(index).AddDays(1) 
     Response.Write(payDates(index)) 
     index +=1 
    NEXT 

本质: payDates的类型是System.Array payDates(index)包含DateTime变量的位置索引,其中指数型int

0

好,AddDays在不是System.Array的成员。但是,您仍然试图调用它:

payDates.AddDays(1) 

如果您试图获取修改日期,请引用数组的日期元素。事情是这样的:

payDates(index).AddDays(1) 

(请注意,如果你正在寻找显示网页上的信息,这是一个很大更好地设置该页面的元素,而不是使用Response.Write()的信息,你也没有控制Response.Write()在结果页面中发出其输出的位置。)