1. OnlineBuff

Is C# is Modern, Type Safe, Versionable and Inter operability Language ?

C# is a modern language

C# is a modern language which enables the developer to build a robust application or web application in quick and easy way.

It is a comprehensive language with many advanced features, especially in version 2.0 such as generics.

It is derived from C++ and Java.


C# is Type Safe Language

C# is Type Safe Language. A programming language is type safe when the language defines the behavior or certain rule set of permission for when the programmer treats a value as a type to which it does not belong.

For Example

string Name = 1; //cause an error
int a = "Hello World"; // cause an error
double db = a; //cause an error

Above example will cause an error for all statements because we cannot add string to integer (cannot implicitly covert type string to int) same way for integer to string and double to int and so on.

The C# language compilers always produce type safe code, which is verified to be type safe during JIT compilation.


Why Type-Safety is Important?

Type safe code can access only the memory locations that it has permission to execute.

Type-safety is important for assembly isolation and security enforcement.

Type safe code cannot read or access values of the private members from another object’s scope

It accesses types only in well-defined, allowable ways, thereby preventing overrun security breaches.

Type safety helps isolate objects from each other and therefore helps protect them from inadvertent or malicious corruption. This isolation helps ensure that assemblies cannot adversely affect each other and it increases application reliability.


How Type Safety Ensured

When a code runs on CLR (Common Language Runtime) it performs the type safe check called type safe verification and this is done during Just in Time Compilation (JIT) by a tool called peverify.exe.


C# is an Inter operability Language

C# includes native support for the COM and windows based applications.

C# allows us to use pointers as unsafe code blocks to manipulate our old unsafe code. Unsafe code for example accessing Microsoft word.

C# can directly access components from vb.net and from other managed code languages runs on CLR.For example if we write a program in VB.NET that program we can access it in C# too by using DLL of vb.net program.


To check c# is an inter operability we will do a simple experiment

Step 1

We will create a Console Application language as visual c#.

Step 2

We will add new Visual Basics Class Library (VB Language) project to our Console Application.

Step 3

We will create a simple class "ClsVBNET" and a simple Add() function which takes two input parameter in our VB project as shown in below snippet of code.

//VB code
Public Class ClsVBNET
    Dim i As Integer
    Public Function Add(ByVal z As Integer, ByVal k As Integer) As Integer
        i = z + k
        Return i
    End Function
End Class   

Step 4

Now we will call VB code class "ClsVBNET" in our Console Application which is using language as C# as shown below.

//C# code
using clsVBNET; // this is namespace

static void Main(string[] args){    
            int answer = 0;
            ClsVBNET objvbnet = new ClsVBNET();
            answer = objvbnet.Add(5,4);
            Console.WriteLine("Add method Output is {0}",answer);          

Step 5
Displaying Output i.e. 5 + 4 = 9


C# Versionable

.NET framework handles the versioning.

Since C# code which runs on .NET framework so it is a versioning language.

In simple words we can upgrade code of an existing running application (i.e. creating a new "DLL" with new version) and that upgraded code we can deploy in the same application without any conflict with the old existing code (Since old code is using different or old version).

We can have different versions of the same component at the same time and our applications will know automatically which version to use and what version not to use.
Note: Versioning is done only on assemblies with strong names.

So this all about features of C-sharp. If you friends have any doubt regarding this topic kindly post your comments. If this article is useful for you kindly share it with your friends. Thanks

Author: Gurunatha Dogi

is a software engineer by profession and founder of Onlinebuff.com, Onlinebuff is a tech blog which covers topics on .NET Fundamentals, Csharp, Asp.Net, PHP, MYSQL, SQL Server and lots more. Follow me @ and twitter.... read more


By Osman mahommed on 2013-09-29
please give me the reasons why c# is widely used instead of the java.

Add a Comment