Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can we create a Static Class in VB.NET? If so, please illustrate. Can we derive a new class from Static class?
Posted

VB.NET Modules are the equivalent of C# Static Classes and no, you cannot derive from a Module (as well as you cannot derive from a C# Static Class).
You may find all the above info better explained inside MSDN documentation.
 
Share this answer
 
You can create static class in vb.net

VB
Friend NotInheritable Class DB
        Public Shared AGE As Integer = 10
    End Class


Using AGE variable in other code

VB
Dim myage As Integer = DB.AGE
 
Share this answer
 
Comments
Dave Kreskowiak 11-May-13 10:14am    
That's not a "static" class as defined by C#. That's an instance class with a static field in it.

The equivilent of a C# static class is a Module in VB.NET.
MorixAL 11-May-13 10:21am    
What about this?
In C# you can put static classes inside static class but in Module you can not put module inside module.
If you define like I wrote you can create classes inside class
Dave Kreskowiak 11-May-13 10:38am    
The problem is that you're not making static classes. You're making classes that cannot be inherited from. There two are not the same.
MorixAL 11-May-13 10:47am    
If you want to use inheritance you can declare class only with Friend keyword, If have tried and it works
Dave Kreskowiak 11-May-13 10:56am    
Uhhh Friend has nothing to do with being able to inherit a class or not. It has everything to do with what code can see it.

Again, you're not making static classes, so all of what you're saying is a moot point.
A VB.NET Module is the equivalent of a static class. You cannot inherit from a static class nor can it be inherited from another class.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900