Click to See Complete Forum and Search --> : static class in vb.net


pradeep_panda
November 11th, 2002, 12:15 AM
i am new to VB.NET
i just wnt to know , how can i declare a class as static...
static and shared key word is not working, as we can not declare them in the class level.

waiting for ur reply...

pradeep

Athley
November 11th, 2002, 07:09 AM
I don't know if I'm missing something here, but isn't a class considered static if all it's member are shared?

/Leyan

pradeep_panda
November 11th, 2002, 07:12 AM
no i am sorry.
but i just want to know is there any way by which i can declare the class as static...
and i donot think that if all the properties and methods are declared static, the class will become static...

Athley
November 11th, 2002, 08:58 AM
I worked vith VB6 before so fully object oriented programming is a bit new to me, so sorry if I'm a bit giddy at times. :)

As I have understood it in the training that I have gone through it is possible to declare members of a class as Shared (static in C#), not classes themselves. The ways to declare a class is described in the help here:

Class Declaration (ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vastmclass.htm)

So the answer to your question would be, no.

What I meant before is not that if all members are static the class BECOMES static, but instead that it might be considered as static. In VB .NET for example the Debug and Trace classes are considered static and as I see it, they are classies containing only Shared members that you can use without creating an instance of the class.

If the sole purpose of yours is to prevent people from being able to create an instance of the class that you are creating, just declare the constructor (Sub New) private.

/Leyan

pradeep_panda
November 11th, 2002, 09:03 AM
thanks for ur reply...
my case is...i started my career in java..so i try to cmpare everything of .net first with java.....by the way i think the private constructor will solve my purpose...it is similar to singleton class in java...

thanks alot