ive got a class that doesn't want to be initiated. that means trying New MyClass should be prohibited
currently im doing this which works:
but is this the "right" approach?Code:Private Sub New
End Sub
Printable View
ive got a class that doesn't want to be initiated. that means trying New MyClass should be prohibited
currently im doing this which works:
but is this the "right" approach?Code:Private Sub New
End Sub
Are you trying to create a singleton class, or do you want a class than can only be inherited (MustInherit) or something else entirely?
NB - the code you gave above doesn't prevent you from creating a new instance of the class at all.
im just using it to store info, i think u can call it a singleton it doesn't have to be inherited.
why doesn't the private new stop an initiation?
i tot it worked, i tried to initiate one and it says i have access restriction
Sorry my mistake - I misread your code.
There are a few ways of creating singletons in vb.net. This one seems to be the most common though.
cool, it does makes sense too i guess, to make it protected in the case of someone else extending
I think what the OP is looking for is either a shared class that can just be used w/o instanciating it... or to have a private constructor, with a shared factory method that will return a new instance of the class.
-tg
yepp something arnd those lines
It would help if you explained exactly what you are trying to do.
Are you providing a class for other people to use or is this just for you?
yepp for others