What is the equivalent of a VB module in C#?


In VB, a module is used to store loose code accessible from elsewhere in the application without having to first initialize something.

The state of the variable can be easily set or changed and that continues to carry on that value throughout.

For the same work in C#< use a static class.

Let us see an example −

VB

Module MyModule
Public Sub Display
MsgBox("Demo!")
End Sub
End Module

C#

public static class Display {
   public static void DisplayMethod() {
      Console.WriteLine("Demo!");
   }
}

Updated on: 22-Jun-2020

645 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements