shared...

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

When you say shared in vb what does it exactly mean... the other languages
use static in the same place of this in .NET here is an example

[Visual Basic]
Public Shared Event Idle As EventHandler

Shared = Static according to the .net documenation ive read... in c++ we
used static to mean a value that stayed there all the time such as a counter
that kept track of how many times a class member was called from any number
of instantiations... for an example... a item that stayed in memory over any
number of instantiations... what does this shared clause mean in vb? is it
similar to what i described or diffrent.. thanks!
 
* "Brian Henry said:
When you say shared in vb what does it exactly mean... the other languages
use static in the same place of this in .NET here is an example

[Visual Basic]
Public Shared Event Idle As EventHandler

Shared = Static according to the .net documenation ive read... in c++ we
used static to mean a value that stayed there all the time such as a counter
that kept track of how many times a class member was called from any number
of instantiations... for an example... a item that stayed in memory over any
number of instantiations... what does this shared clause mean in vb? is it
similar to what i described or diffrent..

VB.NET's 'Shared' is the same as C#'s 'static' (and very similar to
C++'s 'static'). Nevertheless, in VB.NET we say "The shared member
belongs to /all instances/ of a class (even if no instance exists)", in
C# it would read "The static member doesn't belong to any instance, it
belongs to the class".
 
In VB, the "shared" keyword marks the member as shared between all instances
of that class, so I guess you could think it as the same as the "static"
keyword in C++. I don't have much experience in C++, but from your
definition, they are the same.

VB does have a "static" keyword, but this is reserved for local function
variables that persist their state between function calls.

In VB.net a module acts like a shared class - it's the same as a class that
has all its members marked with the "shared" keyword.

Have a look at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vakeyShared.asp

for more information.

HTH,

Trev.
 
thanks, this is what i was thinking it was, i have been searching MSDN for a
meaning of it but never came across just the shared clause... but a bunch of
other stuff named shared :)


Herfried K. Wagner said:
* "Brian Henry said:
When you say shared in vb what does it exactly mean... the other languages
use static in the same place of this in .NET here is an example

[Visual Basic]
Public Shared Event Idle As EventHandler

Shared = Static according to the .net documenation ive read... in c++ we
used static to mean a value that stayed there all the time such as a counter
that kept track of how many times a class member was called from any number
of instantiations... for an example... a item that stayed in memory over any
number of instantiations... what does this shared clause mean in vb? is it
similar to what i described or diffrent..

VB.NET's 'Shared' is the same as C#'s 'static' (and very similar to
C++'s 'static'). Nevertheless, in VB.NET we say "The shared member
belongs to /all instances/ of a class (even if no instance exists)", in
C# it would read "The static member doesn't belong to any instance, it
belongs to the class".
 
Back
Top