InfZero
InfZero

Reputation: 3055

What is language interoperability (basic concept) in .NET Framework?

I'm reading .NET Framework article in Wikipedia, in the first paragraph describes the general concept of this framework, and it says:

It includes a large library and provides language interoperability (each language can use code written in other languages) across several programming languages.

When it declared that .NET provides language interoperability, what is shared: the code or the code functionality?

For example, I have the following simple code:

class Math
{
   public double Pow( double a, double b)
   {
      return Math.Pow(a,b);
   }
}

Do I have access to the C# code or the instantiation of the Math object?

Upvotes: 2

Views: 20107

Answers (5)

Abhinandan Kumar
Abhinandan Kumar

Reputation: 51

All object oriented programming languages provide reusability of code but only with in language whereas .net languages provide cross language re-usability of CIL that is CIL code generated from one .net language can be reused from any other .net language in future and we call this as a language interoperability.

enter image description here

If any two Language wants to interoperate with each other they need to cross two hurdles

  1. Mis-Match in Compiled Code.
  2. Mismatch in Data type.

.Net Overcome both the hurdles and one of the benefit over other languages.

For more details https://www.csharpatoz.com/2017/10/net-basic-1.html

Upvotes: 0

Sam
Sam

Reputation: 1469

Language Interoperability refers to the .NET feature of compile on a common language regardless of the coding language used by the developer. Adding the ability to execute the code supported by a JIT (Just-In-Time) compiler.

The Common Language Runtime or CLR ("common language runtime environment") is a runtime environment for program codes running on the Microsoft .NET platform.

The CLR is the true core of the .NET framework, an execution environment in which applications developed in different languages are loaded, extending the set of services of the operating system (W2k and W2003). It allows to integrate projects in different languages supported by the .Net platform, such as C ++, Visual Basic, C #, among others.

Developers using CLR write the source code in a .NET-compatible language, such as C # or Visual Basic

The CLR is responsible for compiling an intermediate code form called Common Intermediate Language (CIL, formerly known as MSIL, by Microsoft Intermediate Language), to the native machine code, using a compiler at runtime.

To execute it requires a second step, a JIT (Just-In-Time) compiler is the one that generates the actual machine code that is executed on the client platform. This is achieved with .NET independence from the hardware platform. The JIT compilation is performed by the CLR as the program invokes methods. The executable code obtained is stored in the computer's cache, being recompiled again only in the event of a change in the source code.

The CLR should not be confused With a virtual machine, since once the code is compiled, it runs natively without the intervention of an abstraction layer on the underlying hardware. It is an implementation of the Common Language Infrastructure (CLI) standard.

Upvotes: 2

Kendall Frey
Kendall Frey

Reputation: 44384

If you want to use this class in VB.NET, you should have no problem doing so.

Dim math As New Math()
Dim result As Double
result = math.Pow(2, 32)

When .NET code is compiled, it results in MSIL, regardless of what language was used to write it, be it C#, VB.NET, F#, etc. The resulting MSIL code can be used by a different language than the one it was written in.

Almost all of the time, a class written in a language A can be used just as if it was written in language B.

For example, you can write a DLL for special calculations in C++/CLI, and write a program that uses that library in C#. The two are compatible, without having to use interop methods such as P/Invoke.

Most of the .NET Framework itself is written in C#. Yet it is perfectly compatible with VB.NET and friends.

Upvotes: 3

Nick
Nick

Reputation: 4210

Language interoperability is the ability of code to interact with code that is written using a different programming language. Language interoperability can help maximize code reuse and, therefore, improve the efficiency of the development process. Every code written in any .NET language and compiled could be reused from other .NET language.

Upvotes: 7

Chris
Chris

Reputation: 4681

When you compile your C# program, it is compiled into IL (Intermediate Language). That compiled program can then be used by any other .NET language, for example a Visual Basic program could reference yours, create an instance of your Math class and use it.

Visual Basic doesn't care (or know) that your Math class was written in C#, all it sees is a .NET class. That's language interoperability. If VB.NET could only use classes written in VB.NET, and C# could only use classes written C#, those languages wouldn't be interoperable.

Upvotes: 13

Related Questions