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. 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 initialized again, and keeps the same value.

You must know

Declaration context
@Shared is permitted in Class, Struct, Trait, Function, Method, and Sub.
Mixed modifiers
You cannot put @Shared together with most other modifiers. But you can put it together with @Deprecated
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.

Applies to

See also