I have a question about scope here.
Say I have the following module:
Public Module SampleModule
Public Function SampleFunction() As SampleStructure
Return New SampleStructure(123, 456)
End Function
Structure SampleStructure 'Do not want this accessible elsewhere in project
Public A As Integer
Public B As Integer
Sub New(ByVal A As Integer, ByVal B As Integer)
Me.A = A
Me.B = B
End Sub
End Structure
End Module
The function SampleFuncton() is the only code in the entire project that will ever need to create a new instance of SampleStructure. I want the function accessible anywhere in my project, but I do not want the structure accessible anywhere, and I don't want it to show up in Intellisense anywhere else.
Is this even possible?
If what you really want to do is just prevent other assemblies from creating instances of SampleStructure you are looking for the access modifier Friend
Change the constructor of SampleStructure to the following
Friend Sub New(ByVal A As Integer, ByVal B As Integer)
Me.A = A
Me.B = B
End Sub
If you truly want to make the structure accessible only inside your assembly but still have the function accessible to the outside world, you're out of luck.
No, that's not possible. You are returning an instance of the struct so other parts of your program will need to have visibility. How would they be able to interact with it otherwise, or know what type the function returns?
If you were not returning an instance, you could make it private.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With