You are on page 1of 12

.NET 2.

0 and Visual
Studio 2005
SigWin 2004
Outline
 Language enhancements in C#
– Generics
– Partial types
– Anonymous methods
– Nullable types
 IDE features
– Intellisense
– Refractoring
– Code snippets
– Other awesome stuff!
Generics

 Motivation
Generics
 One method:
public int AddSeconds(ArrayList myList) {
int total=0;
DateTime myDate;
foreach (object myObj in myList) {
myDate=(DateTime) myObj;
total+=myDate.Second;
}
return total;
}
Generics

 Other method is to derive your own


collection class. Namespace is now
cluttered with many strongly typed
collections
 Answer to problem: GENERICS!!!!!
Generics: Example

 System.Collections.Generic:

private System.Collections.Generic.List<DateTime> myList;

private Dictionary<string, Stack<DateTime>> myList;


Generics: old example
public int AddSeconds(List<DateTime> myList)
{
int total = 0;
foreach (DateTime myDate in myList)
total += myDate.Second;
return total;
}
Partial types

 Easy way to separate automatically


generated code from your own:

public partial class myClass {}

public partial class myClass {}


Anonymous methods

 Review of delegates
 Anonymous delegate=delegate
without a function name, just code
Anonymous method
example:
button1.Click += delegate { MessageBox.Show("Click"); };

Alternative:
button1.Click+=new EventHandler(myButton1_Click);

private void myButton1_Click(object sender, EventArgs e) {


MessageBox.Show(“Click”);
}
Nullable types
 Motivation
 Syntax:
int? myInt = null;
if (myInt.HasValue)
{
//Do stuff here with myInt.Value
}
else
{
//It's null
}
int? d=1, f=null;
Console.WriteLine(f ?? d);
Visual Studio 2005 IDE

 Demo!

You might also like