tags:

views:

72

answers:

3

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

Regards; Mohammad Mohsin

+2  A: 

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.

LBushkin
@LBushkin : Yes he was asking about the application to be in .Net and within it we write some code in C#, some in J# and some in VB. Can you give a more elaborative reason for the yes?
Mohsin Sheikh Khalid
@moshin Once any .net code is compiled into any .net assembly, it can be referenced by any .net app, regardless of langauge. So you can have a C# dll, a VB.net dll, a J# dll. any of these assemblies could be referenced from an application that was using a different language or one of the above 3. Its really the whole point of the CLR architecture of .net.
David
@LBushkin: That's "CLS compliant", if i'm understanding you right. CLS == Common Language Spec, ie: the rules that say what types can/should be used and how things can/should be named *in order to guarantee interoperability between languages.*
cHao
@cHao: Yes, I meant to write CLS compliant. I'll amend that.
LBushkin
A: 

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.

qstarin
A: 

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.

Ben Robinson