Call Visual Basic Function In C# Page

Sometimes in the real scenario you need to access a function of a VB class in a C# page, so there is nothing different in this scenario. You just need to create the object of the VB class in your C# page and just use it. I will explain it in detail in the following procedure.

Step 1: Create a ASP.NET empty website named "TestApp" using C#.

empty website

Step 2: Create a Web From using C# in the website named "Default.aspx".

Create a Web From

Step 3: Create a class file in the website named "MyClass1.vb" using Visual Basic.

Create a Class

Step 4: Write a function of addition in the VB class that accepts 2 integer values and return the addition of both of the values using another integer variable.

Public Function Add(value1 As Integer, value2 As Integer) As Integer
Dim
result = (value1 + value2)
Return
result
End
Function

Write a function

Step 5: Call the addition function of the VB class in the C# page by creating the object of MyClass1.

Print the addition value on the page.

MyClass1 obj = new MyClass1();
int
addition = obj.Add(2, 3);
Response.Write(addition.ToString());

Call the addition function

Run the page to see the output.

output

Up Next
    Ebook Download
    View all
    Learn
    View all