You can access this property everywhere where you have a reference to a Object of type Class1
. So if your Class2
objects have a reference, they can use it.
For example:
Class Class2
Property cls1 As New Class1
Function getClass1Name() As String
Return cls1.Name
End Function
End Class
Another option is to make the property shared, because it's a value that is independent of any instance of Class1
that makes sense.
Then you can access it without an instance of Class1
via the class-name:
Class Class1
Public Shared ReadOnly Property Name As String
Get
Return System.IO.Path.GetFileName("C:\Demo\Sample1")
End Get
End Property
End Class
Class Class2
Function getClass1Name() As String
Return Class1.Name
End Function
End Class