This blog is subject the DISCLAIMER below.

Sunday, January 28, 2007

What's New in C# 2.0 ? Part 1

in the name of ALLAH

Hope all be Fine ..
as we know that Microsoft announced for C# 3.0 , So I decided to write My Articles about the enhancements in this Language, but before I begin C# 3.0 lets know first the new Adds in
C# 2.0 which was released with Visual Studio 2005 then we will speak about C# 3.0 .

First i will begin with Generics.
Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code.
to use Generics we must use this name space System.Collections.Generic

Example ..
// Declare a list of type int
GenericList list1 = new GenericList();

If you fell that this is not clear look to this problem
Imagine you want to create a class template that supports any type. When you instantiate that class, you specify the type you want to use, and from that point on, your object is "locked in" to the type you chose. How Can you Do this ??

Generic can do this look at the following Example : -

public class ObjectList : CollectionBase
{
private ArrayList list = new ArrayList();
public int Add(ItemType value)
{
return list.Add(value);
}

public void Remove(ItemType value)
{
list.Remove(value);
}

}


Second Partial Classes
Partial classes give you the ability to split a single class into more than one source code (.cs) file. Like This
public partial class MyClass
{
public MethodA()
{...}
}

public partial class MyClass
{
public MethodB()
{...}
}

When you build the application, Visual Studio .NET tracks down each piece of MyClass and assembles it into a complete, compiled class with two methods, MethodA() and MethodB().

In my opinion partial is not Very important for Small projects but it will be great in large projects.

The Second Part Will be about
Iterators
Anonymous Methods
Nullable

No comments: