@Shared

Specifies that an element is related to the class, structure, or procedure in which it is declared, and not some variable.

Instructions

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. With @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 execution in the scope completes. With @Shared, the next time your code calls the procedure, the variable is not re-initialized, and keeps the same value.

Rules

Declaration context
@Shared is permitted in Class, Struct, Trait, Function, Method, and Sub.
Combined modifiers
You cannot combine @Shared with most other modifiers. But you can combine it with @Deprecated
Accessing
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.
Implicitly Shared
Some declarations cannot accept @Shared, but are shared implicitly. These include Const, in all scopes, and all declarations in module scope.

Applies to

See also