Reputation: 362
I just cant seem to understand these pillars of .NET.
Upvotes: 3
Views: 10354
Reputation: 1
CLS stands for Common Language Specification and it is a subset of CTS. It defines a set of rules and restrictions that every language must follow which runs under the .NET framework. The languages which follow these set of rules are said to be CLS Compliant. In simple words, CLS enables cross-language integration or Interoperability.
if we talk about C# and VB.NET then, in C# every statement must have to end with a semicolon. it is also called a statement Terminator, but in VB.NET each statement should not end with a semicolon(;). Explanation of the above Example
So these syntax rules which you have to follow from language to language differ but CLR can understand all the language Syntax because in .NET each language is converted into MSIL code after compilation and the MSIL code is language specification of CLR.
Common Type System (CTS) describes the datatypes that can be used by managed code. CTS defines how these types are declared, used and managed in the runtime. It facilitates cross-language integration, type safety, and high-performance code execution. The rules defined in CTS can be used to define your own classes and values.
CTS deals with the data type. So here we have several languages and each and every language has its own data type and one language data type cannot be understandable by other languages but .NET Framework language can understand all the data types.
Upvotes: 0
Reputation: 1818
CTS is a formal specification describing type properties:
CLS facilitates interoperability between .NET languages at the IL level:
For example:
Foo()
and
foo()
are the same thing.Upvotes: 3
Reputation: 7201
Some examples would certainly help here.
One of the key things that is not CLS-compliant is unsigned numbers (e.g., uint). Another is function pointers (delegates). If it's not going to make sense on both ends of the line, then it's not "common"; CLS defines a set of common types that work not only within the CLR, but also within certain common and well-specificed interop scenarios.
If you want to enforce CLS compliance, you can add the "CLSCompliant" attribute to an assembly by adding it to the assemblyinfo.cs file in a project.
[assembly: CLSCompliant(true)]
You can also add it as an attribute on a class.
[CLSCompliant(true)]
public class HospitalLocationEntity : EntityBase
{
...
}
Doing these things will cause the C# compiler (or VB, with appropriate VB syntax on the attributes) to raise compile errors for CLS compliance violations.
Also, adding the [ScriptService] and [ScriptMethod] attributes to web services (.asmx) will cause the service to generate JSON service output, and will require that the data used for service responses be marked as CLSCompliant at class and assembly levels.
<System.Web.Services.WebService()> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
<ScriptService()> _
Public Class HospitalLocationService
Inherits System.Web.Services.WebService
<WebMethod()> _
<ScriptMethod()> _
Public Function GetAll() As List(Of HospitalLocationEntity)
Return (New HospitalLocation()).GetAll().Data
End Function
End Class
Upvotes: 0
Reputation: 17499
As already mentioned, CLS is subset of CTS. But there is much more in the actual definition of these terms.
I suggest reading CLR via C#.
Upvotes: 0
Reputation: 16577
CTS (Common Type System) So you can say CTS describes how types are declared, used and managed in the runtime and facilitates cross-language integration, type safety, and high performance code execution.
CLS (Common Language Specification) The Common Language Specification (CLS) is an agreement among language designers and class library designers to use a common subset of basic language features that all languages have to follow.
As you can see in the image CLS is a subset of CTS
alt text http://www.microsoft.com/taiwan/msdn/columns/DoNet/images/NET_CTS1.gif
Upvotes: 2