Posts

Showing posts from September, 2010

IE 9 Beta

IE 9 beta is available for download at http://www.beautyoftheweb.com/

ASP.NET 4.0 Feature - MetaKeywords and MetaDescription Properties

Image
Let us see the new feature in ASP.NET 4.0 know as the “MetaKeywords and MetaDescription Properties”. These are new runtime properties added for search engine optimization. Which otherwise means that it will help for search engines searching for relevant pages. We can use the same as seen below in the code behind file in the page_load The other way to implement this is in the page directive section on the aspx page as seen below Hope this was cool feature. Please add your comments or suggestions. Cheers!!!

ASP.NET 4.0 Feature - URL Routing

Image
Let’s see the new feature in ASP.NET 4.0 known as “URL Routing”. URL Routing is a feature which is driven by the ASP.NET URL routing engine which enables the application to route to custom urls instead of actual urls which may have some querystrings etc. In the past we have seen urls like http://localhost/NewStore/Titles.aspx can be now show as http://localhost/NewStore/AllTitles or http://localhost/NewStore/Titles.aspx?ID=2 can be now shown as http://localhost/NewStore/Products/Fiction . Doesn’t this look great? Now let’s see how do we achieve this. We would be using the “System.Web.Routing” class which products us a method “MapPageRoute” which helps to do the routing. Let us see a simple example where we would have two pages one which shows All the Titles and another which shows Title for a specific Author Id. For this example I am using the Pubs Database. We would have to first create the two new Pages “Titles.aspx” and “TitlesbyAuthor.aspx” . Now the “Titles.aspx” shows All the Tit

ASP.NET 4.0 Feature - Clean Web.Config

Image
Lets see the feature in ASP.NET 4.0 which is known as “Clean Web.config” . If we have noticed the web.config in the previous version ASP.NET 3.5 it would be about 125lines . In ASP.NET 4.0 you would be surprised to see as shown below The only information that is available is enabling debugging . Wow.. Don’t you feel we have a clean web.config !!!! Hope this was cool feature. Please add your comments or suggestions. Cheers!!!

C# 4.0 Feature - CoVariance and ContraVariance

Lets see the new feature in C# 4.0 “CoVariance and ContraVariance". This is a very tricky concept and there are many illustrations in the web. If we had to do the following prior to C# 4.0 class Drivers { } class LaptopDriver : Drivers { } class DesktopDriver : Drivers { } class LanDriver : LaptopDriver { } delegate T GetDriver (); static void Main(string[] args) { GetDriver getLaptopDriver = () => new LaptopDriver(); GetDriver getDrivers = getLaptopDriver; Console.ReadLine(); } We would have got a error as follows Cannot implicitly convert type 'ConsoleApplication2.Program.GetDriver ' to 'ConsoleApplication2.Program.GetDriver ' To overcome this in C# 4.0 we have CoVariance which is mainly used for assignment compatability. We need to modify the code by adding a “out” keyoword in the delagate declaration as seen below class Drivers {

C# 4.0 Feature - Dynamic Keyword

Lets look into new C# 4.0 feature, “Dynamic” keyword. In the past we always used to type cast objects to a particular object or datatype if the available value is of another type. For eg: We have created a Employee Class public class Employee { public int EmployeeID { get; set; } public string EmployeeName { get; set; } } Now we have a InitilaizeEmployees() method, which has a written type as object public object InitializeEmployee() { Employee emp = new Employee(); emp.EmployeeID = 1; emp.EmployeeName = "Jack"; return emp; } Now if we had to assign the object “obj” to a employee object we had to type cast with “Employee” for eg: If we write Employee emp = InitializeEmployee(); We will get a compile type error, since it is not of the same type hence we will have to write as Employee emp =(Employee) InitializeEmployee(); To ease this we have a new keyword known as “Dynamic

C# 4.0 Feature - Named Arguments

Let’s discuss about the new feature in C# 4.0 “Named Arguments”. As seen in the last post regarding “Optional Arguments”, we would have wondered for the “Add” method we had three parameters. But If we wanted to pass the first and third parameters instead of second , Is this possible ? Lets see the code below private int Add(int i, int j = 1, int k = 0) { return i + j + k; } private void button1_Click(object sender, EventArgs e) { MessageBox.Show(Add(2, 3).ToString()); } This will look like we are passing for value “i” and “j” and not “k”. So how can we achieve this ? In C#4.0 we have a new feature called “Named Arguments” where we can pass arguments with the parameter name : . The above code would be rewritten as follows private void button1_Click(object sender, EventArgs e) { MessageBox.Show(Add(2,k:3).ToString()); } Hope this was cool feature. Please add your comments or suggestions. Cheers!!!

C# 4.0 Feature - Optional Arguments

The feature that we are discussing today is called as “Optional Arguments”. Prior to C#4.0, whenever we need to pass optional parameters for a method, we used to use method overloading . For eg: private int Add(int i) { return i + 2; } Now if the Add method wanted to accept two parameters then we used to write as follows private int Add(int i, int j) { return i + j; } Now if the Add method wanted to accept two parameters then we used to write as follows private int Add(int i, int j, int k) { return i + j + k; } Eventually we had to write three overloaded methods based on the number of parameters passed and invoke the method based on the parameters passed. In C#4.0, we can rewrite the code by declaring parameters as optional as follows private int Add(int i, int j = 1, int k = 0) { return i + j + k; } When invoking this method and need only one parameter to be passed use it as

Back to Blogging ........

I have been missing from blogging for sometime since April. I am mostly on twitter @shaju or on facebook @ shajuthomas . But I intend to come back to blogging which i started way back in 2003. I was quite busy with my daily work schedules, but i know thats not a good reason from staying away. Hope to gain the momentum back again. See you all........ Happy Weekend.... God Bless you all....... Cheers!!!