.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Interoperability between vb.net and C# languages.

Posted By:Ravi Ranjan Kumar       Posted Date: October 28, 2011    Points: 200    Category: .Net Framework    URL: http://www.dotnetspark.com  

This visual article enable you to understand about Interoperability between vb.net and C# languages.

Interoperability :- 
According to Wikipedia Interoperability is a property referring to the ability of diverse systems and organizations to work together (inter-operate). The term is often used in a technical systems engineering sense, or alternatively in a broad sense, taking into account social, political, and organizational factors that impact system to system performance.

The .NET Framework (pronounced dot net) is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability (each language can use code written in other languages). Programs written for the .NET Framework execute in a software environment (as contrasted to hardware environment), known as the Common Language Runtime (CLR), an application virtual machine that provides important services such as security, memory management, and exception handling. The class library and the CLR together constitute the .NET Framework. 

In short 
Because computer systems commonly require interaction between new and older applications, the .NET Framework provides means to access functionality that is implemented in programs that execute outside the .NET environment. Access to COM components is provided in the System.Runtime.InteropServices and System.EnterpriseServices namespaces of the framework; access to other functionality is provided using the P/Invoke feature.

How to make Interoperability program between C# and vb.Net

here I am going to create a simple .dll using vb.net languages for simple arithmetic calculation of two parameter. and then calling these .dll using C# code to display the accomplishment of Interoperability feature.

How to design vb.Net code 

Follow the procedure step by step to design dll using vb.net

and then you can write simple given code for manipulating arithmetic calculation of two values. have a look four function name ADD,Subs,Mult and Div having two parameter in each function. 
Public Class Arithmatic
    Public Shared Function ADD(ByVal x As Double, ByVal y As Double) As Double
        Return x + y
    End Function
    Public Shared Function Subs(ByVal x As Double, ByVal y As Double) As Double
        Return x - y
    End Function
    Public Shared Function Mult(ByVal x As Double, ByVal y As Double) As Double
        Return x * y
    End Function
    Public Shared Function Div(ByVal x As Double, ByVal y As Double) As Double
        Return (x / y)
    End Function
End Class
now Compile program, while compiling program you will get message like given below.. [ .dll file have been created ]

you can see the VBMath.dll file at corresponding directory as bin directory of your program. 

How to design C# application 

after creating library using vb.net its time to create C# application to use Interoperability program. let see how to design C# program and what code need to write.

its will open your program. now you need to right click on program name like(PrgrmIntrprbltyCheck) resides in Solution Explorer) and then Click on Add Reference mention in below image.

It will open Add Reference window. now navigate appropriate .dll file as Example VBMath.dll ) for adding for further coding.

Now the given code is influencing the concept how to use library written in vb.net languages with C# languages. code will show program for Simple Calculation of two numeric values.

using System;
using System.Collections.Generic;
using System.Text;

namespace PrgrmIntrprbltyCheck
    class Program
        public static void Display(double res, string condition)
            Console.WriteLine("The " + condition + " of two number is : " + res);
        static void Main(string[] args)
            char ch;
            Console.WriteLine("Enter Your Option");
            Console.WriteLine("1 For Addition");
            Console.WriteLine("2 For Substraction");
            Console.WriteLine("3 For Multiplication");
            Console.WriteLine("4 For Devision");
            Console.WriteLine("Enter your Option");
            int op = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the First Value");
            double n1 = double.Parse(Console.ReadLine());
            Console.WriteLine("Enter the First Value");
            double n2 = double.Parse(Console.ReadLine());

                switch (op)
                    case 1:
                        Display(VBMath.Arithmatic.ADD(n1, n2), "Addition");  // Here VBMath.Arithmatic.Add(n1,n2) is function written in VB.Net
                    case 2:
                        Display(VBMath.Arithmatic.Mult(n1, n2), "Substraction");
                    case 3:
                        Display(VBMath.Arithmatic.Mult(n1, n2), "Multiplication");
                    case 4:
                        Display(VBMath.Arithmatic.Div(n1, n2), "Devision");

                        Console.WriteLine("Invalid Option Try again...");

                Console.WriteLine("Do you want to Carry On...");
                ch = char.Parse(Console.ReadLine());
            while (ch == 'y' || ch == 'Y');



you can see here how Function written in vb.net langues is accessing here. its just because of Interoperability supported by .Net framework. 

Now run program for getting how application working..

Reference Link :- Link 1-[ http://en.wikipedia.org/wiki/Interoperability ]
                           Link 2- [ http://en.wikipedia.org/wiki/.NET_Framework ]

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend