Sunday, November 02, 2008

C# 4.0: Optional and Named Parameters - CTP Release

C# Chief Architect Anders Hejlsberg explained the future of C# in PDC2008.Initial CTP release of C# 4.0 has a feature of Optional and Named Parameters.

I have already explained the another featire of C# 4.0 is Dynamic Programming in my previous post.

Here I am going to explain about Named and Optional Parameters.

C# 1.0, 2.0, 3.0 doest not have a feature of Optional parameter. But in VB, we can define a method with an optional parameters.

Developers facing some difficulties of not having an optional parameter in C# especially when communicating with COM object.

C# 4.0 going to have a feature of Optional Parameter.

In previous version of C#, we have to implement multiple overloaded methods to have a variable parameters in the function like

C# 3.0:

public int Add(int x, int y)
return x + y;

public int Add(int x, int y, int z)
return x + y + z;

C# 4.0 (Optional Parameter):

public int Add(int x, int y, int z = 0)
return x + y + z;


Here we can declare the parameter as an optional by initializing the value to the variable.

if we have multiple optional parameter in a function, we have to initialize the value sequentially in VB like


Public Function Add(ByVal x As Integer, ByVal y As Integer, Optional ByVal z As Integer = 5, Optional ByVal a As Integer = 10) As Integer

Return x + y + z + a

End Function

From the above code, it has 2 optional parameter. we can't pass value to parameter "a" without passing value for parameter "z".

// Calling
Add(1, 2, 5, 15)

C# 4.0 - Named Parameter
public int Add(int x, int y, int z = 5, int a = 10)
return x + y + z + a;


From the above code, it has 2 optional parameter. But here we can pass a value to parameter "a" without passing a value for "z" by using name of parameter like a:15.

C# 4.0 : Dynamic Programming -- CTP Release

C# Chief Architect Anders Hejlsberg explained the future of C# in PDC2008.Initial CTP release of C# 4.0 has some features like

1. Dynamically Typed Objects.
2. Optional and Named Parameters
3. Improved COM Interoperability.
4. Co and Contra Variance.

Here I am going to explain about Dynamic Programming.

Dynamically Typed Objects:

Here is the code for traditional way of calling typed object methods.

EmployeeInfo eInfo = new EmployeeInfo();
eInfo.EmployeeID = 1;
eInfo.FirstName = "Ayyanar";
eInfo.LastName = "Jayabalan";

Employee emp = GetEmployee();
bool affected = emp.AddEmployee(eInfo);

From the above code, we know the type "Employee" to call the AddEmployee methods.

if we does not know the Type("Employee"), we can use Reflection to call the AddEmployee method.

Here is the code to call the method using Reflection.

object refEmp = GetEmployee();

Type type = refEmp.GetType();

object objAffected = type.InvokeMember("AddEmployee", System.Reflection.BindingFlags.InvokeMethod, null, null, new object[] { eInfo });

bool affected = (bool)objAffected;

C# 4.0:

We can call method directly without using Reflection for UnKnown Typed object.

dynamic emp = GetEmployee();

bool affected = emp.AddEmployee(eInfo);

We have to declared as a "dynamic" for unknown typed objects.

Method calling decision taken at RUNTIME instead of COMPILE TIME.

And also, .Net does not throw error while compiling the code and does not provide INTELLISENSE for dynamic type.

Saturday, November 01, 2008

Microsoft Azure Services Platform

The Azure™ Services Platform (Azure) is an internet-scale cloud services platform hosted in Microsoft data centers, which provides an operating system and a set of developer services that can be used individually or together. Azure’s flexible and interoperable platform can be used to build new applications to run from the cloud or enhance existing applications with cloud-based capabilities. Its open architecture gives developers the choice to build web applications, applications running on connected devices, PCs, servers, or hybrid solutions offering the best of online and on-premises.

Click here to know more about Azure.

What is the Azure Services Platform?

Why use the Azure Services Platform?

Visual Studio 2010 and Framework 4.0 - CTP Release

Microsoft released the CTP version of Visual Studio 2010 and Framework 4.0.

Here is the link to download.

Sunday, October 26, 2008

Next Generation Developer Tool : Visual Studio 2010 and .Net Framework 4.0

Visual Studio 2010 and the .NET Framework 4.0 mark the next generation of developer tools from Microsoft. Designed to address the latest needs of developers, Visual Studio and the .NET Framework deliver key innovations in the following pillars:

Democratizing Application Lifecycle Management
Application Lifecycle Management (ALM) crosses many roles within an organization and traditionally not every one of the roles has been an equal player in the process. Visual Studio Team System 2010 continues to build the platform for functional equality and shared commitment across an organization’s ALM process.
Enabling emerging trends
Every year the industry develops new technologies and new trends. With Visual Studio 2010, Microsoft delivers tooling and framework support for the latest innovations in application architecture, development and deployment.
Inspiring developer delight
Ever since the first release of Visual Studio, Microsoft has set the bar for developer productivity and flexibility. Visual Studio 2010 continues to deliver on the core developer experience by significantly improving upon it for roles involved with the software development process.
Riding the next generation platform wave
Microsoft continues to invest in the market leading operating system, productivity application and server platforms to deliver increased customer value in these offerings. With Visual Studio 2010 customers will have the tooling support needed to create amazing solutions around these technologies.
Breakthrough Departmental Applications
Customers continue to build applications that span from department to the enterprise. Visual Studio 2010 will ensure development is supported across this wide spectrum of applications.

Click here to know more.

Wednesday, June 25, 2008

Solution: Session Timeout not working on Production Server in ASP.Net


You may faced the session timeout problem on production web server after deployed the ASP.Net Web Application. Even after you have changed the Web.Config setting like

<sessionState mode="InProc" cookieless="false" timeout="300"/>

Session will get lost after default session timeout duration (20 Minutes).

You may also have tried to change the default session timeout value in IIS (Internet Information Server).

In all the above cases, session timeout value is lost after 20 Minutes (default session timeout value).


Here is the solution to maintain the session for long period (above 20 minutes) on Production Web Server. To maintain the session, we have to refresh the website atleast before 20 minutes (e.g every 10 minutes). To refresh the website, here is the tricky solution.

ASP.Net 2.0 Web Project:

Instead of refreshing each ASPX page, we can achieve this with single webform.
Add a new webform (RefreshASPXToKeepSessionAlive.aspx) in the web project. Add the metatag information within HEADER of this web page.

<head runat="server" >
<meta http-equiv="refresh" content="600" />
<title>Poll this page from master page to keep session alive</title>

The above META tag information says refresh the page for every 600 seconds (10 Minutes).

Master Page:

You have to call the above created page from MASTER PAGE. you can call this without affecting other web forms master design, use the hidden iframe logic like.

You have to use above iframe HTML tag outside the content placeholder.

The above technique refresh the RefreshASPXToKeepSessionAlive.aspx page from master page for every 20 Minutes. So, website will maintain the session for long period (greater than 20 Minutes) without losing.

if you got any problem on using the IFRAME tricks, add the iframe tag dynamically in HTML view instead of adding that in design time.


if (Session["IsUserLogged"] != null && ((bool)Session["IsUserLogged"]) == true)
Response.Write("<iframe src ='RefreshASPXToKeepSessionAlive.aspx' style ='display:none'></iframe>");

Saturday, May 31, 2008

Source Code Analysis for C# - StyleCop

Microsoft released the tool for source code analysis for C#.Currently MS developed this only for C# not for VB. Microsoft using this for their internal purpose also. They have named this as "StyleCop". Earlier, MS released the tool called "FxCop" that analyse the compiled binaries but "StyleCop" analyse the source code. It provides the set of rules for style, documentation ,readability, etc. Currently they have defined around 200 rules. Those rules are not Customizable.But you switch ON/OFF the rules depending on your needs or company standard.

They have covered the following catagory rules:

1. Documentation
2. Layout
3. Maintainability
4. Naming
5. Ordering
6. Readability
7. Spacing

Screenshot of rules in StyleCop:

Screenshot of using this tool in application:

The ultimate goal of the source code analysis tool is allow you to give clean , consistant code with team members and for others who view your code with more readability.

Click here to download the Source Code Analysis Tool

Wednesday, March 12, 2008

Official Trip to US

Here are the pictures that took at Austin, TX

click this link to see more photos..