Silverlight 3 Released

Microsoft has released Silverlight 3. I installed Silverlight 3 (available from Microsoft download site here) on my laptop – as usual it was a fast download and install experience.


Also download the Visual Studio 2008 (SP1) tools for Silverlight 3 from Microsoft download center here.


After the installation is complete the successful install message is shown –


If you have Beta version of Expression Blend or any Expression product, you’ve to uninstall it.


Installing the Silverlight 3 tools VS 2008 (SP 1) would give you all the project templates required for creating Silverlight 3 projects –


Here’s a excellent blog post on Silverlight 3 features –
I would blog more about Silverlight 3 in later posts.


UML is Visual Studio Team System 2010

Till now, mostly I’ve covered the features of developer edition of Team System. The Architecture edition of VS2010 also has undergone lot of changes. One of the primary ones surely is re-introduction of UML tools in VS2010 – that does not mean Microsoft is going away from DSL (Domain Specific Languages) – in fact the UML diagrams are implemented using DSL.

The other interesting part is Microsoft has joined OMG (Object Management Group), the group who maintains the specification of UML (Unified modeling language) – You can read details about it here and here.

To start using UML diagrams in VS2010, create a modeling project – VS 2010 comes with a default modeling project template – select it while creating a new project in New Project dialog –


VS 2010 supports six different types of UML diagrams –

  • Activity Diagram
  • Use Case Diagram
  • Layer Diagram
  • Logical Class Diagram (different from Class Diagram or Physical Class Diagram available in VS 2008).
  • Component Diagram and
  • Sequence Diagram

VS 2010 has default templates for all these diagram types – they can be accessed from Add New Item dialog box –


Logical Class Diagram in VS 2010:


As you can see it’s possible to use different relationships in class diagrams like (Dependency, Association, Inheritance/Generalization) –


Use Case Diagram:


As you can see, it’s possible to use all the features of Use Case diagram like – Actor, Use Case, Include, Extend etc.


Sequence Diagram:


Layer Diagram:


Read more about Layer diagram in Skinner’s blog. It’ also possible to use layer diagram to validate your architecture and ensure that code is following the layer diagram (and in turn architecture).

Auto Implemented Properties in VB 10

One of the focus areas and strategy for both VB10 and C# 4 (released with .NET Framework 4 and VS 2010) of “co-evolution”, which means that when adding a major feature to one language it would be added in all the languages. Till .NET Framework 3.5 we’ve seen certain important features existing in both VB and C# that do not exist in their counterparts.

C# 3.0 introduced a feature called Auto-Implemented Property – in case the developer does not want to use code in get and set parts of properties, they can use Auto Implemented Property, where compiler automatically generates backup variables –

Normal Property (C#):

public class Employee


        private string _firstName;

        public string FirstName




                return _firstName;




                _firstName = value;





Auto Implemented Property (C#):


public class Employee


        public string FirstName { get; set; }



Now VB 10 also have introduced auto implemented properties similar to C# 3.0 –

Normal Property (VB):

Public Class Employee


    Private _firstName As String

    Public Property FirstName() As String


            Return _firstName

        End Get

        Set(ByVal value As String)

            _firstName = value

        End Set

    End Property


End Class


New Auto Implemented Property (VB):


Public Class Employee


    Property FirstName() As String


End Class


Omitting the bracket after property name is also allowed –


Public Class Employee


    Property FirstName As String


End Class


In case of C#, the compiler automatically generates the private backup field/variable that holds the value of the property as shown below.


Similarly, in case of VB also the compiler generates the backup field/variable that holds the value of the property – the compiler names it as _ appended by property name (in this case _FirstName). It will also fill in the property’s getter and setter.


VB 10 goes a step forward and allows to initialize or set the default value of the property while declaring it –

Property FirstName As String = "Aniruddha"

The default values is set in the constructor by the complier, which can be seen by inspecting the ctor in ILDASM (highlighted) –


I know that C# programmers would be jealous by the default value thing.

Auto-implemented properties cannot have parameters, nor can they be declared ReadOnly or WriteOnly.

.NET Framework 4: new BCL features – BigInteger

In my previous blog post about .NET Framework and CLR 4, I mentioned that, apart from performance and other improvements in .NET Framework like DLR (Dynamic Language Runtime) related stuff, Code Contract (Design by Contract – earlier available as separate download from Dev Labs) there has been improvements in .NET 4 BCL (Base Class Library) like

  • System.Numerics namespace
    • BigInteger data type
  • Tuple<T> – used extensively in DLR and Dynamic languages IronPython, IronRuby
  • SortedSet<T>
  • IO related improvements

In this blog post I’ll discuss about the new BigInteger feature – the other two Tuple and SortedSet would be discussed next.


.NET Framework 4 Base Class Library (BCL) has a new structure called BigInteger. There has been a steady demand of BigInteger class in .NET community and within programmers for a long time – the new BigInteger class meets the demand. The class resides in new System.Numerics class – in fact the new Namespace currently (as of Beta 1) has just a single class called BigInteger.

BigInteger Represents an arbitrarily large signed integer. BigInetger is a nonprimitive integral type that supports arbitrarily large integers. Each integral primitive, such as Byte or Int32, includes a MinValue and a MaxValue property, which define the lower bound and upper bound supported by that data type. In contrast, the BigInteger structure has no lower or upper bound, and can contain the value of any integer.

Here’s how to initialize and use BigInetger. BigInteger can be initialized in following two ways –

  • By using new keyword (similar to initializing a reference type).

  // Use new keyword
BigInteger bigInt1 = new BigInteger(999999999999999999);

 ·         You can declare a BigInteger variable and assign it a value just as you would any numeric type, as long as that value is an integral type.

 // Assign BigInteger an integral value.
BigInteger bigInt2 = 999999999999999999;

·         Assign a decimal or floating-point value to a BigInteger object if you cast the value or convert it first.

// Assign decimal or floating-point value to BigInteger object
BigInteger bigInt3 = (BigInteger)999999999.99999999;

·         Call Parse or TryParse methods to convert the string representation of a number to a BigInteger.

// Call Parse or TryParse methods to convert the string representation of a number to a BigInteger

            string positiveString = "91389681247993671255432112000000", negativeString = "-90315837410896312071002088037140000";

            BigInteger posBigInt = 0, negBigInt = 0;



                posBigInt = BigInteger.Parse(positiveString);



            catch (FormatException)


                Console.WriteLine("Unable to convert the string ‘{0}’ to a BigInteger value.", positiveString);



            if (BigInteger.TryParse(negativeString, out negBigInt))



                Console.WriteLine("Unable to convert the string ‘{0}’ to a BigInteger value.", negativeString);

  • Use BigInteger static methods like (Abs, Pow, Log etc) which returns a BigInteger value to initialize a BigInteger.

// Use BigInteger static methods to initiaze BigInteger
BigInteger bigInt4 = BigInteger.Abs(2343243243243243243);
BigInteger bigInt5 = BigInteger.Pow(99999999999999999, 10);

Here’s the code snippet and it’s output –

.NET Framework 4 and CLR 4

One of the first things to notice after installing .NET Framework 4, is a new folder representing framework 4 (v4.0.20506) got added in Framework folder – Windows Folder\Microsoft .NET\Framework. Notice the version no in folder name 4.0.20506 – there are other folders representing older .NET Frameworks 3.5, 3.0, 2.0, 1.1 and 1.0 (each represented as sub folders).


The property of System.dll in version 4 folder confirms the version no as 4.0 (4.0.20506). This version no also shows up when you check the property of System assembly within Visual Studio.


.NET Framework 4.0 also comes with a brand new version of Common Language Runtime (CLR) – CLR 4. 3.5 SP1, 3.5, 3.0 and 2.0 versions of .NET Frameworks all used the same version of CLR – CLR 2. With .NET Framework 4.0 there is a new CLR – CLR 4.


Apart from performance and other improvements in .NET Framework like DLR (Dynamic Language Runtime) related stuff, Contract (Design by Contract – earlier available as separate download from Dev Labs) there has been improvements in .NET 4 BCL (Base Class Library) like

  • System.Numerics namespace
    • BigInteger data type
  • Tuple<T> data structure – used extensively in DLR and Dynamic languages IronPython, IronRuby
  • SortedSet<T> data structure
  • IO related improvements

I’ll discuss the BCL improvements in a separate blog post next time – Happy coding in VS 2010/.NET 4

What’s new in C# 4.0 – dynamic programming

C# version 4.0 that comes with .NET Framework 4.0 and VS 2010 comes with some new language features and enhancements. Though the major in the list of new features surely would be dynamic programming and DLR, other features are also of importance. Here’s a list of the important new features introduced in C# 4.0 –

·         Late Binding/Dynamic Programming Support through DLR and dynamic keyword
·         Named and Optional Parameters
·         Improved COM Interop
·         Covariance and Contravariance
·         Co-evolving C# and VB – bringing down the gap between C# and VB languages

In this blog post I would discuss about Dynamic programming / Late Binding support in C# 4.0 with dynamic keyword. I would discuss about other features in future blog posts.

Late Binding/Dynamic Programming Support through DLR and dynamic keyword

From the inception days itself C# has been designed and architected as a Static programming language – that is binding to all method calls are done at compile time by the compiler. If the C# compiler does not find a suitable/appropriate method during phase, it gives a compilation error – that’s been the story from day 1 of C# 1.0 (rather from beta days). So the following lines code would give a compile time error –


On the other hand VB.NET has supported late binding from day 1 because of it’s history and acquaintance with Basic, Visual Basic. So it is not as statically typed as C# is – and in this scenario in allows us to do late binding. So the corresponding piece of code in VB.NET compiles and shows an output of 11

C# 4.0 introduces a new keyword called dynamic that supports late binding – keep in mind that dynamic is a static type in itself. So now rather than using object we can use dynamic. This does not mean that C# is now going away from static typing. When the compiler finds dynamic it uses DLR (Dynamic Language Runtime) to bind the method calls instead of C# Object Binder.

This code snippet compiles successfully and produces a correct output of 11. One interesting info: when dynamic keyword is used, VS 2010 IDE recognizes it and just tells that the operation would be resolved at run time (rather than showing members, as it could not know what the members are).


If the member is not found at runtime (i.e. DLR could not bind/resolve to the mentioned member name), a RuntimeBinderException is thrown –


It’s also possible to use dynamic type (which is a static type) as method parameter and return type –

static void Main(string[] args)


string str = "Hello from dynamic";
int len = CalculateLength(str);
Console.WriteLine("Length is {0}", len);


private static dynamic CalculateLength(dynamic value)


return value.Length;


It’s also possible to declare dynamic variables at class level –


dynamic d = "Hello from dynamic";

static void Main(string[] args)


int len = d.Length;
Console.WriteLine("Length is {0}", len);


As I mentioned, DLR helps languages bring late binding into .NET world as CLR is primarily designed for static-typing. Here’s how languages Dynamic languages like IronPython, IronRuby and CLR based languages like C#, VB.NET uses DLR –

Without DLR scenario:

With DLR:


So as you can understand one of the main concepts behind C# 4 is dynamic programming and dynamic languages. If you remember in C# 3.0 it was functional programming with local variable inference, automatic properties, Lambda expressions etc. So with both the releases of C# 3.0 and 4.0, C# team has caught up with the language trends –


So here’s a overall picture of the C# journey till date –

There are lot of resources about dynamic/DLR. Following are some –

Keep Learning C# 4.0 and .NET 4 – Aniruddha