0

有人可以解释为什么我获得一个初始化为 New List(Of) 的对象的 NullReference 异常吗?

Module Module1
  ' MAIN =================================    
  Sub Main()
    Console.Clear()
    Console.WriteLine("Creating Bar")
    Dim myBar As New Bar()
    Console.ReadLine()
  End Sub    
End Module

Class Foo
  Public Overridable Property Test As String

  Public Sub New()
    Me.Test = "hello"
  End Sub
End Class

Class Bar
  Inherits Foo
  Private _MyString As New List(Of String)

  Public Sub New()
    MyBase.New()
  End Sub

  Public Overrides Property Test As String
    Get
      Return MyBase.Test
    End Get
    Set(value As String)
      MyBase.Test = value
      ' NULL REFERENCE EXCEPTION ???????!!!!!!!!!!!
      Console.WriteLine("{0}, and _MyString.Count = {1}", MyBase.Test, Me._MyString.Count)
    End Set
  End Property
End Class
4

1 回答 1

2

Foo.New()Bar().

New部分As New List(Of String)实际上是Bar.New()构造函数的一部分,它在MyBase.New().

于 2012-09-25T14:54:04.863 回答