C#, J# and VB.NET is it possible to write a class in each and make its variables interact in one application?

StackOverflow https://stackoverflow.com/questions/3239475

  •  15-09-2020
  •  | 
  •  

Question

I was asked this question in an interview would appreciate your answers.

Regards; Mohammad Mohsin

Was it helpful?

Solution

It's unclear exactly what the original interviewer meant - but if he was asking whether it's possible to combine code in .NET written in C#, J#, and VB.NET - the answer is yes - as long as each class is in a separate assembly. You cannot compile code from multiple languages into a single assembly.

As long as the code written in each is CLS compliant - you should be able to refer to the types and properties declared regardless of language. Language neutrality is one of the core design principles of .NET.

To answer your question from the comments... When you compile code i any .NET language, it is compiled into a common, intermediate representation which preserves metadata and type information. The .NET runtime is therefore able to load and interoperate code that may have been written in different .NET languages. This flexibility is made possible by several features of .NET, including the common type system, the CLR, and MSIL.

OTHER TIPS

Yes, those languages all compile to a common intermediate language and all run in the managed framework.

If you wrote a class in each language (you would have a class library project for each), you could use those classes together in any project using a language targeting the .Net runtime.

It depends what you mean. Any public members on a class can be accessed, it would not matter what language the class was written in. They would need to be compiled into separate assemblies though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top