Posts

Showing posts from April, 2012

New features of C# 4.0-Named and Optional Parameters

The new release of Visual Studio.NET 2010 and Microsoft.NET Framework 4.0, we have new features added to the C# language. The new features being integrated with the new version of the language C# 4.0. Here is a list of new features added to C# 4.0. •Dynamic programming •Named and optional parameters •Covariance and Contravariance   Named and Optional Parameters Another new feature is named and optional parameters. Optional parameters allow giving a method parameter a default value, so you don't have to specify it every time you call the method (see Listing 3). using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CSharpNewFeatures { class Program { public static void Method(int age, String firstname="Vijayanand", double salary=60000.99) { } static void Main(string[] args) { Method(30); //The same as Method(30,"Vijayanand",60000.99) Method(30, "Vijayanand"); //The same