-2

我有一个 ClassA 类,在其中创建另一个 ClassB 类的对象(classB_obj)。如何使用这个 classB_obj 访问/设置 ClassB 内部结构的值?我不熟悉 vb.net 中的语法。我想做的是这个

Public ClassA
         Public Sub SomeSub 
              Dim ClassB_obj As New ClassB()   

              Dim classB_struct As ClassB.sampleStruct 'The error is **Type ClassB.sampleStruct not defined**
          End Sub
End ClassA

Public ClassB

   Private Structure Struct
       Dim xy As String
       Dim yz As String
   End Structure

   Dim sampleStruct As Struct

   'Member functions here
 End ClassB

错误是Type ClassB.sampleStruct 未定义

谁能告诉我哪里出错了。这里是 vb.net 的新手,不熟悉语法。非常感谢

4

2 回答 2

0

您需要声明Class B允许在类外访问的成员以Public

Public ClassB

   Public Structure Struct
       Dim xy As String
       Dim yz As String
   End Structure

   'Public sampleStruct As Struct

End ClassB

Public ClassA
   Public Sub SomeSub 
        'Dim ClassB_obj As New ClassB()   
        Dim classb_struct As ClassB.Struct
   End Sub
End ClassA
于 2012-09-14T00:58:25.847 回答
0

好吧,您的结构是私有的,您是否尝试过将其公开?

于 2012-09-14T00:58:44.790 回答