Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Quoted from A Brief Introduction To IL code, CLR, CTS, CLS and JIT In .NET

CLS stands for Common Language Specifications. It is a subset of CTS. CLS is a set of rules or guidelines which if followed ensures that code written in one .NET language can be used by another .NET language. For example one rule is that we cannot have member functions with same name with case difference only i.e we should not have add() and Add(). This may work in C# because it is case-sensitive but if try to use that C# code in VB.NET, it is not possible because VB.NET is not case-sensitive.

Based on above text I want to confirm two points here:

  1. Does the case-sensitivity of IL is a condition for member functions only, and not for member properties?
  2. Is it true that C# wouldn't be inter-operable with VB.NET if it didn't take care of the case sensitivity?
share|improve this question
2  
Why dont you try it out? there are actual practical problems that you might encounter, but this doesnt look like one of them. For example: stackoverflow.com/questions/12085131/… –  Dave Hillier Nov 2 '13 at 18:28
    
well, put here for someone already learned to answer. discussion with the learned ones always let me learn something that I do not learn in practicing without theory. –  Ali .NET Nov 3 '13 at 9:33

2 Answers 2

The restriction on case-sensitivity applies to all members (fields, methods, properties) visible to other assemblies. Thus, the following is OK:

[CLSCompliant(true)]
public class C
{
    private int i;
    public int I { get { return i; } set { i = value; } }
}

but the following isn't:

[CLSCompliant(true)]
public class C
{
    public int i;
    public int I { get { return i; } set { i = value; } }
}

and the following isn't either:

[CLSCompliant(true)]
public class C
{
    protected int i;
    public int I { get { return i; } set { i = value; } }
}

since a VB.NET class might want to inherit from class C.


If the second example above were in a C# library and a VB.NET project would try to use it, the following code would not compile:

Dim c As New C()
Console.WriteLine(c.I)

This is the compile-time error that the VB.NET compiler would throw:

'I' is ambiguous because multiple kinds of members with this name exist in class 'C'.

share|improve this answer

Does the case-sensitivity of IL is a condition for member functions only, and not for member properties?

C# properties are implemented internally as special methods called accessors so the above quote applies to both methods and properties.

Is it true that C# wouldn't be inter-operable with VB.NET if it didn't take care of the case sensitivity?

Theoretically, it may be possible to write C# that is compatible with VB.NET. However, it is not just case sensitivity. For example, the many keywords appear in one language and not the other need special syntax (which C# and VB.NET both provide). Unsigned types cannot be exposed and operators cannot be overloaded. For more details, see http://stackoverflow.com/questions/570452/what-is-the-clscompliant-attribute-in-net.

Rather than manually having to check these, Microsoft created CLS as a way of programmaticly enforcing it. More importantly, it also allows languages other than VB.NET and C# to interoperate through a common runtime, including hose that lack a special syntax for invalid identifiers.

share|improve this answer
    
Well, I was surprised to know that C# case-sensitivity could be a problem in interoperability b/w the two. I always had in my conscious that somehow compiler would be emitting the managed code to handle this. Anyways.. In your second response, would you want to say that any keyword that is not shared by both languages would make the code non-interoperable? like if we write obj = null in C# it would not be usable in VB.NET because the later understands obj = Nothing? –  Ali .NET Nov 3 '13 at 12:32
    
@Ali.NET Keywords are only problematic in identifiers only, such as class and method names. For example, a class called MustInherit might be fine in C# might may cause problems in VB.NET. –  akton Nov 3 '13 at 20:57
1  
The point about keywords is not true, both C# and VB have a special syntax for using keywords as identifiers (@keyword in C#, [keyword] in VB). –  svick Nov 4 '13 at 11:40
    
@svick Good point. Forgot that. Updated the answer. –  akton Nov 4 '13 at 23:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.