Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,
Assume that I have library file written in C#, which has 2 methods. As we know C# is case sensitive language. We can write two methods with same name. For eg.

Class MyClass
{
   public int Mymethod()
   {
     return 1;
   }

   public int mymethod()
   {
     return 2;
   }
}

If I want to use this library file into my vb.net project, Will it allow me to that?
How come .net interoperability will be achieved as if VB.NET is not case sensitive?
I think compiler will put some code or we have to specify some parameter while compiling library file. I not sure about my answer. Please clear my doubt.

Thanks,
Posted
Updated 29-Jul-11 9:49am
v2

Yes you can use a C# class in VB.Net. This can be achieved because all .Net languages ultimately target the Common Type System.
Read more about language interoperability here[^].
 
Share this answer
 
v2
Actually, you are right, that will cause a problem.

If you follow the link that Abhinav S gave you, you'll see another link to:

http://msdn.microsoft.com/en-us/library/12a7a7h3(v=vs.71).aspx[^]

Which gives the Common Language Specification -- basically the set of rules you must follow in order for your class to be guaranteed to interoperate with other .NET languages.

In particular it states:

"Characters and casing: ...For two identifiers to be considered distinct, they must differ by more than just their case."

and:

"Uniqueness: All names within a CLS-compliant scope must be distinct..."

So, basically the class you propose would not be CLS-compliant and therefore would not be interoperable with other .NET languages. The documentation does not guarantee what will happen if you try to do that. (Hopefully you'd end up with an intelligible error message somewhere along the way.)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 2-Aug-11 3:30am    
Good, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900