【发布时间】:2014-05-28 18:53:07
【问题描述】:
使用以下 Visual Basic 类:
Public Class Student
Public Property StudentName As String
Public Property Scores As Integer()
End Class
以下示例代码行由我正在阅读的一本教科书提供:
arrList.Add(New Student With {.StudentName = "name", .Scores = New Integer() {98, 92, 81, 60}})
但是这行没有'New Integer()'声明的代码似乎工作得很好:
arrList.Add(New Student With {.StudentName = "name", .Scores = {98, 92, 81, 60}})
我不明白为什么我需要使用“New Integer()”声明。在这种情况下,'New Integer()' 声明是否发生了其他事情,或者是不必要的代码?
【问题讨论】:
-
你用的是什么版本的VB.net?
-
如果您使用的是VS2008,则需要使用教科书中的示例。
-
使用 VB 2013,但文字是 VB 2008,所以 VS2008 评论非常有助于理解为什么我可以省略“新”。
标签: vb.net