We are testing interview quizzes and created a demo app. Now, We require your help. Please take this quiz and provide inputs for content improvement. Interview Quiz




Nice reference for C# evolution

CsharpCsharp

While going through some posts on MSDN, I came across this beautiful image which can be termed as a one stop solution for C# evolution. This is a gift reference, I would like to share with my friends and readers and I know, this will help them like it helped me. This is a revisit to all the steps which are required to know our growth as a C# Developer.

Although, Matrix is very much clear on its own but we can revisit the concepts one more time.

csharpevolution

csharpevolution

C# 1.0

Managed Code

Before that, We should know Unmanaged Code.

Unmanaged Code: Unmanaged code is compiled to machine code and therefore executed by the Operating System directly.It is sometimes referred to as Native Code. Unmanaged executable files are basically a binary image, x86 code, loaded into memory.It is compiled and run directly on the processor it was designed for.It is fast and simple. As it interacts directly with operating system so this is always considered damaging and unsecured plus there are many factors like type safety checking, memory management, and destruction of unneeded objects that are additional tasks required to be performed.

Managed Code: Managed code is code that has its execution managed by the .NET Framework Common Language Runtime. It does not interact directly with the Operating System or machine but this code gets converted to an intermediate language with the help of CLR. When we run the code,just before that, the IL is compiled into native executable code. CLR enforces managed execution environment that ensures type safety, array bound and index checking, exception handling, and garbage collection.The idea behind is to provide a secure environment or framework for development which interacts with the machine or operating system through a defined boundary.

 

C# 2.0

Generics

Generic Class:

We are talking reusability here. We got bored of creating similar classes again and again so we thought of creating type independent class and C# guided with their generics feature. Generics helped us to create classes that can take any type and at the point of instantiation, type can be provided to the class to make it one specialized class. With Generics,There is no need to create same kind of class for different types then.

Example

Before generics


public class Products

{

private int _productid;

private ListGetProducts()

{

//Implementation

}

}

//One more class

public class Category

{

private int _categoryid;

private ListGetCategory()

{

//Implementation

}

}

If we look at these classes, then we can easily identify that these can be changed to a  generic class. Here, List<> is a collection.

Now after applying Generics.


public class Generics<T>

{

private int _genericid;

private List<T> Get<T>()

{

//Implementation

}

}

Here, T identifies the type that is going to be provided while instantiating the class like


Generics<Product> generics= new Generics<Product>();

Note: Generic class provide runtime type safety.

Generic Collections:

We can use collections with generics and take advantages like

  1. Compile time creation of type safe collection.
  2. Code reusability
  3. Improved Performance
  4. Avoid Boxing ad Unboxing
  5. Strong Type Checking

Example


ListstringList= new List();

Anonymous Methods

Anonymous methods can be termed as an extension of delegates. Delegates is a very broad topic and requires one article in itself so we will explain later.

RIght Now,Anonymous methods can be used in the place where there is a use of a delegate so lets write a delegate.


 

//Declare a delegate

delegate void DelegateExample();

//Declare method following delegate signature

void Example1(){//Implementation

}

//Create instance of delegate and wrap the function

DelegateExample delegateExample = new DelegateExample(Example1);

//Or

DelegateExample delegateExample = Example1;

//Finally call the instance

delegateExample();

Now, we will change the delegate instantiation to accommodate anonymous method


//Declare a delegate

delegate void DelegateExample();

//Create instance of delegate and wrap the function without any function name

DelegateExample delegateExample =

delegate(){

//Example1 Implementation

}

//Finally call the instance

delegateExample();

Nullable Types

Refer this article

We will talk about rest of the feature in next article.

Navigation: