Web Design that taps into the haromny and vision of your dreams.

The .Net Common Language Specifications

The C# language, defined

Written By on in C#

442 words, estimated reading time 3 minutes.

In an object-oriented environment such as C# and the .Net platform, everything is an object. Once an object is created it needs to be able to communicate or interact with other objects, and the object may need to be manipulated.

Introduction to the .Net Framework Series
  1. What is Microsoft .Net?
  2. Benefits of using the .Net Framework
  3. Languages in the .Net Framework
  4. The C# vs Visual Basic Question
  5. Common Language Runtime
  6. The .Net Common Language Specifications
  7. Global Assembly Cache (GAC)

These other objects may have been created in a different language, for example, C++. Other languages such as C++ define data types differently (a good example is a string, which in C++ is a pointer to a null-terminated character array). If you were to pass a string to that external method you would need to convert your C# string object into a pointer to an array of characters which has been terminated with a null character.

This approach can get complicated, and sometimes many type conversions are required. This not only leads to messy code but also causes an unwanted performance overhead and a lapse in concentration by the programmer can lead to unwanted memory leaks and unstable applications.

Common Type System

The .Net platform overcomes this problem by implementing the Common Type System (CTS). The Common Type System means that every language in .Net uses the same data types (or objects). When you declare a string in C# you are creating an instance of a string class. When you define a string in Visual Basic, you create an instance of the same string class, thus when you pass parameters between languages there is no longer any requirement to convert data types.

In the .Net framework types are split into two different categories: value types and reference types.

Value Types

A value type directly contains its data. A variable of type int contains a value (e.g. 12345) and only a value. Each variable of a value type has its own copy of the data. An operation on one variable does not affect another. Value types are stored in a memory location known as the stack.

Reference Types

Reference types contain a reference, or memory location, of their data. The data is stored as an object on the heap. Unlike value types, two or more reference types can point to the same memory location, thus an operation on one variable can affect another. Reference types are instantiated with the new keyword.

Base Class Library

.Net Base Class Library
.Net Base Class Library

Another feature of the Common Language Specifications is that of the Base Class Library. The Base Class Library provides a common set of classes that all .Net languages can utilise. These classes range from a standard Windows form class to classes for temperature, coordinates, data access, XML parsers and so on.

The Base Class Library is divided up into namespaces so that they are easily navigable. For example, the SqlConnection class is located in the System.Data.SqlClient namespace. By using this namespace C#, VB, C++ J# and so on can all interact with the same SqlConnection class, all access the same properties and methods.

Last updated on: Friday 23rd June 2017

 

Comments

There are no comments for this post. Be the first!

 

Leave a Reply

Your email address will not be published.





If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me