How can we make our C# classes to interoperate with other .net languages ?

 Posted by Chvrsri on 1/27/2011 | Category: C# Interview questions | Views: 5203 | Points: 40
Answer:

We must make sure that our C# classes conforms to th Common Language Subset(CLS).

For this we need to add a global assembly to our C# source files

Which can be depicted as :

[assembly: CLSCompliant (true)]


If we use a C# feature which is not CLS-Compilant the compiler will emit an error.


Source: My Own !!! | Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Questpond on: 1/27/2011 | Points: 10
Hello ,
CLS stands for common language specification and not subset.

If you follow CLS then any .NET language can call your code. For instance c# is case sensitive while VB.NET is not. So when you code in VB.NET something like this below

public sub x()


end sub

public sub X()

end sub


The above code will compile for VB.NET but C# will be confused as c# is case sentive and VB.NET is not. So what you need to do is go in your assemblyinfo.cs and put the below attribute.

[assembly: CLSCompliant (true)]


With the above code any kind of CLS compliance you break you will get a warning.


http://www.questpond.com/dotnet/Top-Dot-Net-Interview-Questions-and-Answers-Part1.html

Login to post response