Specifies that an element is related to the container in which it is declared, and not some instance of that container.
When you make an element with
@Shared in a class or structure, the member is available to all instances.
Usually each instance keeps a different copy.
@Shared, you can make a variable that all instances of a class have access to, but other code cannot.
When you declare a local variable with
@Shared in a procedure, it keeps its value between procedure calls.
Usually a local variable releases its memory when control moves out of the scope.
@Shared, the next time your code calls the procedure, the variable is not initialized again, but keeps the same value.
You must know
- Declaration context
@Sharedis permitted in
- Mixed modifiers
- You cannot put
@Sharedtogether with most other modifiers. But you can put it together with
- You get access to a shared member of a class or structure through its qualified name.
That is the name of the class or structure, a dot (
.), and the name of the member. You cannot get access to a shared member through a variable of the class or structure.
- Always shared
- Some declarations cannot accept
@Shared, but are shared the same. These include
Const, in all scopes, and all declarations in module scope.
- Dim Statement
- Function Statement
- Method Statement
- New Statement
- Object Statement
- Property Statement
- Sub Statement