📘 VB.
NET – Creating a Class Library
A Class Library in VB.NET is a collection of reusable classes and methods compiled into a
DLL (Dynamic Link Library).
You can use this DLL in multiple projects without rewriting the code.
🔹 Steps to Create a Class Library in Visual Studio
1. Open Visual Studio → Go to File → New → Project.
2. Select Class Library (VB.NET) from project types.
3. Give your project a name, e.g., MyLibrary.
4. Write your class code inside it. Example:
' Inside MyLibrary project
Public Class Calculator
Public Function Add(ByVal a As Integer, ByVal b As Integer) As
Integer
Return a + b
End Function
Public Function Subtract(ByVal a As Integer, ByVal b As Integer)
As Integer
Return a - b
End Function
End Class
5. Build the Project → It will create a MyLibrary.dll file in the project’s bin\Debug folder.
🔹 Using the Class Library in Another Project
1. Create a Console Application (or Windows Forms app).
2. Right-click on References → Click Add Reference.
3. Browse and select MyLibrary.dll.
4. Use the library in your program:
Imports MyLibrary ' Import your DLL namespace
Module Program
Sub Main()
Dim calc As New Calculator()
Console.WriteLine("Addition: " & calc.Add(10, 5))
Console.WriteLine("Subtraction: " & calc.Subtract(10, 5))
Console.ReadLine()
End Sub
End Module
🔹 Output
Addition: 15
Subtraction: 5
🔹 Advantages of Class Library
✅ Reusability → Same DLL can be used in many projects.
✅ Modularity → Separates business logic into separate components.
✅ Maintainability → Easy to update the DLL without touching main app code.
✅ Encapsulation → Hides internal code details, exposing only required methods.
⚡ Example in Real Life:
● The System.dll or System.Data.dll in VB.NET are just class libraries provided by
Microsoft.
● You use them by writing:
Imports System
Imports System.Data