S
Simon Woods
Hi
I'm pretty new to vb.net and have a question because I'm not sure when to
use Shared as part of the method declaration. I understand, from my reading,
that this applies the method to the class rather than each object created
from that class, but I don't understand the applicability of this.
So for example, I have a business object working in the middle tier. I have
a collection class, MyBusinessObjects, which has a Function GetData and
returns a MyBusinessObject.
e.g.
Public Class MyBusinessObjects
Public Function GetData(KeyList() as String) as MyBusinessObject
....
or
Public Shared Function GetData(KeyList() as String) as
MyBusinessObject
...
End Class
So when I'm using this collection in my code, I could
Dim _MyBusinessObjects as New MyBusinessObjects
For Each _MyBusinessObject as MyBusinessObject in
_MyBusinessObjects.GetData(Keylist())
...
Next
or using the Shared declaration I could
For each _MyBusinessObject as MyBusinessObject in
MyBusinessObjects.GetData(Keylist())
...
Next
Perhaps my example isn't a very good one, but when should I use Shared and
when not?
Thanks
Simon
I'm pretty new to vb.net and have a question because I'm not sure when to
use Shared as part of the method declaration. I understand, from my reading,
that this applies the method to the class rather than each object created
from that class, but I don't understand the applicability of this.
So for example, I have a business object working in the middle tier. I have
a collection class, MyBusinessObjects, which has a Function GetData and
returns a MyBusinessObject.
e.g.
Public Class MyBusinessObjects
Public Function GetData(KeyList() as String) as MyBusinessObject
....
or
Public Shared Function GetData(KeyList() as String) as
MyBusinessObject
...
End Class
So when I'm using this collection in my code, I could
Dim _MyBusinessObjects as New MyBusinessObjects
For Each _MyBusinessObject as MyBusinessObject in
_MyBusinessObjects.GetData(Keylist())
...
Next
or using the Shared declaration I could
For each _MyBusinessObject as MyBusinessObject in
MyBusinessObjects.GetData(Keylist())
...
Next
Perhaps my example isn't a very good one, but when should I use Shared and
when not?
Thanks
Simon