Posts Tagged ‘VS 2010’

Tuple in C# 4.0

Posted: November 29, 2009 in .NET, C#
Tags: ,

Tuple provides us with a way to group elements of disparate data types together.This is present in functional languages like Haskell and also dynamic languages like Python.A common example of a tuple is a pair of coordinates defining a point in two dimensional space.In Haskell a tuple storing name and age of person is defined as :

(more…)

Advertisements

Laziness in C# 4.0 – Lazy<T>

Posted: October 4, 2009 in .NET, C#
Tags: , ,

Lazy Instantiation” defers creation of an object till the time it is actually accessed.The process of object creation is always expensive as it involves allocation of memory on the heap.So Lazy Instantiation optimizes resources by using them when it is actually required.Till C# 3.0 we needed to some custom coding to implement “Lazy Instantiation” pattern.Now C# 4.0 introduces the Lazy<T> class as part of BCL for this purpose.In this post we will take a detailed look into the behavior and functioning of this class.

(more…)

Dynamic in C# – Part3

Posted: September 19, 2009 in .NET, C#
Tags: , ,

In the last two posts we have discussed about dynamic languages and how DLR allows dynamic languages to run on CLR.In this post we will take a look into the new “dynamic” type in C# and how it works internally.

Let us take a look into the following lines of code:

(more…)

In my last post I had discussed about optional arguments and default values.In continuation to that today we will take a look into the named arguments feature.Let us consider the method definition and invocation as shown below:


class Program {
       static void Main(string[] args) {
           Foo f = new Foo();
           f.PrintName("Sankarsan", "S", "Bose");
           Console.ReadLine();
       }
   }
   public class Foo {
       public void PrintName(string firstName, string lastName, string middleName ) {
           Console.WriteLine("Name is {0} {1} {2}", firstName, middleName, lastName);
       }

}

Here the PrintName method is invoked using what is called positional arguments where the value of the parameters are determined by their position in the parameter list.In C# 4.0 we can do it like this using named arguments:

(more…)

I have recently downloaded the Visual Studio 2010 Beta 1 and started looking into the .NET Framework 4.0/IDE features.In the next couple of posts I will be discussing about these.To start with I have chosen optional parameters and default values.This feature is nothing new and has been there in languages like C++ for quite long.We will first take a look how we can use this in C# and how it is implemented.The following lines of C# code shows a method where the parameter middleName is optional and client is forced to pass a blank string value there as the parameter is not optional.
(more…)