0% found this document useful (0 votes)
6 views

Whidbey Tutorial

This document summarizes new features in .NET 2.0 and Visual Studio 2005, including: 1) Language enhancements in C# such as generics, partial types, anonymous methods, and nullable types. 2) IDE features in Visual Studio 2005 like IntelliSense, refactoring, and code snippets. 3) Examples of using generics to define strongly typed collections instead of object arrays, partial types to separate generated and custom code, anonymous methods for event handling, and nullable types to allow null values for non-nullable types.

Uploaded by

VENKATESH PAI
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Whidbey Tutorial

This document summarizes new features in .NET 2.0 and Visual Studio 2005, including: 1) Language enhancements in C# such as generics, partial types, anonymous methods, and nullable types. 2) IDE features in Visual Studio 2005 like IntelliSense, refactoring, and code snippets. 3) Examples of using generics to define strongly typed collections instead of object arrays, partial types to separate generated and custom code, anonymous methods for event handling, and nullable types to allow null values for non-nullable types.

Uploaded by

VENKATESH PAI
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 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