What's
New in the .NET Framework 2.0
1) SQL Server integration
.NET Framework 2.0, Visual Studio 2005 and SQL Server 2005
are all now tied together — meaning that these three products are now released
in unison.
2) 64-Bit support
More and more enterprises are moving to the latest
and greatest 64-bit servers from companies such as Intel (Itanium chips) and
AMD (x64 chips) and the .NET Framework 2.0 has now been 64-bit enabled for this
great migration.
Microsoft has been working hard to make sure that
everything you build in the 32-bit world of .NET will run in the 64-bit world.
This means that everything you do with SQL Server 2005 or ASP.NET will not be
affected by moving to 64-bit. Microsoft themselves made a lot of changes to the
CLR in order to get a 64-bit version of .NET to work. Changes where made to
things such as garbage collection (to handle larger amounts of data), the JIT
compilation process, exception handling, and more.
Moving to 64-bit gives you some powerful additions.
The most important (and most obvious reason) is that 64-bit servers give you a
larger address space. Going to 64-bit also allows for things like larger
primitive types. For instance, an integer value of 2^32 will give you
4,294,967,296 — while an integer value of 2^64 will give you
18,446,744,073,709,551,616. This comes in quite handy for those applications
that need to calculate things such as the U.S. debt or other high numbers.
3) Generics
In order to make collections a more powerful
feature and also increase their efficiency and usability, generics were
introduced to the .NET Framework 2.0.
To utilize generics in your code,
you will need to make reference to the Collections.Generic
namespace. This will give you access to generic versions of the Stack,
Dictionary, SortedDictionary, List and Queue classes. The following demonstrates the use of a generic
version of the Stack class:
void
Page_Load(object sender, EventArgs e)
{
System.Collections.Generic.Stack<string> myStack =
New System.Collections.Generic.Stack<string>();
myStack.Push("St. Louis Rams");
myStack.Push("Indianapolis
Colts");
myStack.Push("Minnesota Vikings");
Array myArray;
myArray = myStack.ToArray();
foreach(string item in myArray)
{
Label1.Text += item + "<br
/>";
}
}
4) Anonymous methods
Anonymous methods enable you to put programming steps within a delegate that you can then later execute instead of creating an entirely new method. For instance, if you were not using anonymous methods, you would use delegates in a manner similar to the following:
public partial class Default_aspx
{
void Page_Load(object sender, EventArgs e)
{
this.Button1.Click += ButtonWork;
}
void ButtonWork(object sender, EventArgs e)
{
Label1.Text = "You clicked the button!";
}
}
But using anonymous methods, you can now put these actions directly in the delegate as shown here in the following example:
public partial class Default_aspx
{
void Page_Load(object sender, EventArgs e)
{
this.Button1.Click += delegate(object
myDelSender, EventArgs myDelEventArgs)
{
Label1.Text = "You clicked the button!";
};
}
}
When using anonymous methods, there is no need to create a separate
method. Instead you place the necessary code directly after the delegate
declaration. The statements and steps to be executed by the delegate
are placed between curly braces and closed with a semicolon.5) Nullable types
Due to the fact that generics has been introduced into the underlying .NET Framework 2.0, it is now possible to create nullable value types — usingSystem.Nullable<T>
. This is ideal for situations such as creating sets of nullable items of type int
. Before this, it was always difficult to create an int
with a null value from the get-go or to later assign null values to an int
.To create a nullable type of type
int
, you would use the following syntax:
System.Nullable<int> x = new System.Nullable<int>;
There is a new type modifier that you can also use to create a type as nullable. This is shown in the following example:
int? salary = 800000
6) Partial Classes
Partial classes are a new feature to the .NET Framework 2.0 and again C# takes advantage of this addition. Partial classes allow you to divide up a single class into multiple class files, which are later combined into a single class when compiled.To create a partial class, you simply need to use the
partial
keyword for any classes that are to be joined together with a different class. The partial
keyword precedes the class
keyword for the classes that are to be combined with the original class. For instance, you might have a simple class called Calculator
as shown here:
public class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
}
From here, you can create a second class that attaches itself to this first class as shown here in the following example:
public partial class Calculator
{
public int Subtract(int a, int b)
{
return a - b;
}
}
When compiled, these classes will be brought together into a single
Calculator class instance as if they were built together to begin with.
No comments:
Post a Comment