New Features of C# 3.0

1. Extension Methods : You can define extension methods to your namespace, so that if this is added, the class in which it is applied will act as instance variable. Example :

pubic void isDateTime(this string x)
{
return DateTime.TryParse(x);
}

The function will be added to the string object, and you can use it normally as with instance methods of String class.

2. Annonymous Types : You can create unnamed objects that is not derived from a class, rather it is created on a fly. Annonymous types comes very handy when working with LINQ.
Example :

var x = new {x=20,y=40};


thus x will have 2 properties x and y.

3. Initialisers : While you create object of a class, ,we now dont need to call its constructors as all the public properties can be initialised easily.
MyClass x = new MyClass {
MyProperty1 = 20,
MyProperty2 ="This is new Property "};

thus we can set properties directly without calling the respective constructors. This feature also comes very handy when we dont want to have lots of constructors overloads or just say we have to create 2 constructors with same set of parameters but which will be assigned to 2 different properties . Accessing properties directly is very handy feature lately.

Also there is collection initialisers like
List mycol = {"ss","gg"};
You can do this without calling add method.


4. Implicitely Typed Variables : C# introduces "var" which means when the object is assigned the type will be determined automatically. if you assing a string to x it will be of string type, or whatever you do.

5. Partial Methods : .NET 3.5 introduces partial methods, where the same methods can be declared more than once so that when called it will automatically add features to the existing method that is already defined.
Note : Partial methods must not return anything, it should be defined as Void.

6. Property implementation is not required : Sometimes we just need to define properties to expose objects. In such case we dont need to implement a property, rather we can go with auto implementation feature introduced.

public string myproperty {get;set;};

The property will implicitly create a private variable and assign the values properly.

7. LINQ and Lambda Expression : You can query .net objects now using Linq. Lambda expressions are short - hand representation of LINQ queries. :)

This is just basics of what introduced in C# 3.0. I will discuss more on each of them when I find time.

Hope you like reading this.
Read Disclaimer Notice

Comparision between Response.Redirect, Response.RedirectParmanent and Server.Transfer

It is to be noted, .NET has lately introduced Response.RedirectParmanent() after a long time. The main motive is to have permanent response redirection to the Search Engines.

Response.RedirectParmanent() is an extension function introduced in .NET 4.0.
The main motive of it is to indicate the Response Code to the Search Engine that the page is moved permanently. The Response.Redirect generates Response code as 302 whereas RedirectParmanent returns 301.

Thus say you have a page, and which is included to search engine for a long time, if you use Response.Redirect() it will not change this effect to the search engine(taking this a temporary change), while if you use Response.RedirectParmanent() it will take it as permanent.

If you try to write Response.RedirectParmanent() the code will look like :

public static class Extensions
{
public static void RedirectPermanent(this HttpResponse Response, string absoluteUri)
{
Response.Clear();
Response.Status = "301";
Response.RedirectLocation = absoluteUri;
Response.End();
}
}

In case of Server.Transfer() the actual response is actually been updated. There is no effect to the search engine, and search engine will think the output is coming from the same page that is called upon. Let us give an example :

Say you have 2 pages (Page 1 and Page 2) where Page1 redirects to Page2
In case of

1. Response.Redirect() : Search Engine will take this redirection as Temporary(Status 301) and always keep Page1 in its cache.
2. Response.RedirectParmanent() : Search Engine will take this a permanent redirection(Status 302) and will remove Page1 from its database and include Page2 for better performance on search.
3. Server.Transfer() : Search Engine will be unaware of any redirection been took place (Status 200) and will keep Page1 to its database. It will think Page1 is producing the output response of Page2.

When to use:
Response.Redirect is perfect when your page is temporarily changed and will be changed to original within a short span of time.
Response.RedirectParmanent() when you are thinking of deleting the Page1 totally after the search engines changes its cache.
Server.Transfer() when you are thinking of keeping the page for ever, and to let search engine unaware of this redirection.

Thanks for reading and hope you like the discussion.
Read Disclaimer Notice

Async support for Silverlight and WP7

Async support in C# language brings the new life to the modern application development to bring forth the same technique of writing your code and bring asynchrony easily. The main focus of async ctp is to ornament the language in such a way so that the developer could seamlessly create applications that brings asynchrony yet not dealing with its complexity. Hence using the new technique, asynchrony could easily achieved in a program without refactoring the whole program with lots of callbacks and method calls. I have already talked about it in a separate article. If you don’t know, please visit “Async CTP 5.0”.


Async CTP is released again recently and announced in MIX 11. Just after it is released, the first thing that everyone looks for is what is new in the release. As a matter of fact, I did jumped back to see them but eventually found out that there is nothing new in this build in terms of new features is concerned but the release focuses on fixes of performance adding debugging capabilities etc. I will definitely look back to them later in another post, but in this post I am going to talk about another important thing that featured with this release. As opposed to the previous release, the current release now supports Silverlight and Windows Phone 7 environments. This seems to be interesting.

What is Asynchrony?

The word asynchrony means something that is running without blocking other operations running in parallel. If you have created a background Thread to process some data, you are actually doing asynchronous job in background as your foreground operation does not get hampered. In vNext C# introduces Asynchrony using TPL. The two new keywords “async” and “await” could be used to make one sequential method asynchronous. Hence the new way of developing asynchronous program replaces the traditional approach where we needed to refactor the code totally to gain asynchrony in our application. Basically, this is done using the StateMachine to store the entire method into a form of states, and each states are delegated into batch of statements. The Task.ContinueWith is used in the system to ensure that the method body gets executed sequentially. Yes, it’s a compiler trick. If you want to know more about it, please read through my entire article on “Async CTP”.

Read Disclaimer Notice