I have tried to show by example how to use VB components in C#. As I am beginner for .NET technologies, so always try to use easiest examples so that it is easy to get for beginners.
Hello World program in VB (hellovb.vb).
Imports System
Namespace hellovb
Public Class HelloString
Public Function GetString() As String
Console.WriteLine("Hello World in Visual Basic Program")
End Function
End Class
End Namespace
Compile it using vbc /t:library hellovb.vb.
This command will generate hellovb.dll.
Hello World program in C# (hellocs.cs).
using System;
namespace hellocs
{
public class displayA
{
public void Displayhello()
{
Console.WriteLine("Hello in C# Program");
}
}
}
Compile it using csc /t:library hellocs.cs.
This command will generate hellocs.dll.
Main program(in c#) in which we will use these libraries.
Main Program in C# (maincs.cs).
using System;
using hellocs;
using hellovb;
class maincs
{
public static void Main()
{
hellovb.HelloString vb = new hellovb.HelloString(); // namespace.classname of
hellovb.vb
vb.GetString(); //Calling vb function
hellocs.displayA cs = new hellocs.displayA(); // namespace.classname of hellocs.cs
cs.Displayhello(); //Calling vb function
}
}
Compile it using command csc maincs.cs /r:hellocs.dll;hellovb.dll.
Output will be.
Hello World in Visual Basic Program.
Hello in C# Program.