Click here to Skip to main content
12,747,448 members (36,521 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
Can we create a Static Class in VB.NET? If so, please illustrate. Can we derive a new class from Static class?
Posted 2-Jan-12 3:38am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You can create static class in

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

Using AGE variable in other code

Dim myage As Integer = DB.AGE
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.
ArioSolution 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.
ArioSolution 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.
ArioSolution 11-May-13 11:19am
You maybe right Dave,
But tell me what about module inside module?

It's sample, go to and write something in c#.
Convert it and you can see that the static class is converted to NotInheritable class.
Dave Kreskowiak 11-May-13 11:34am
Sigh... The converter is making an approximation. NOT a static class.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170215.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100