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, MyBusinessObjec ts, which has a Function GetData and
returns a MyBusinessObjec t.
e.g.
Public Class MyBusinessObjec ts
Public Function GetData(KeyList () as String) as MyBusinessObjec t
....
or
Public Shared Function GetData(KeyList () as String) as
MyBusinessObjec t
...
End Class
So when I'm using this collection in my code, I could
Dim _MyBusinessObje cts as New MyBusinessObjec ts
For Each _MyBusinessObje ct as MyBusinessObjec t in
_MyBusinessObje cts.GetData(Key list())
...
Next
or using the Shared declaration I could
For each _MyBusinessObje ct as MyBusinessObjec t in
MyBusinessObjec ts.GetData(Keyl ist())
...
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, MyBusinessObjec ts, which has a Function GetData and
returns a MyBusinessObjec t.
e.g.
Public Class MyBusinessObjec ts
Public Function GetData(KeyList () as String) as MyBusinessObjec t
....
or
Public Shared Function GetData(KeyList () as String) as
MyBusinessObjec t
...
End Class
So when I'm using this collection in my code, I could
Dim _MyBusinessObje cts as New MyBusinessObjec ts
For Each _MyBusinessObje ct as MyBusinessObjec t in
_MyBusinessObje cts.GetData(Key list())
...
Next
or using the Shared declaration I could
For each _MyBusinessObje ct as MyBusinessObjec t in
MyBusinessObjec ts.GetData(Keyl ist())
...
Next
Perhaps my example isn't a very good one, but when should I use Shared and
when not?
Thanks
Simon
Comment