Upload
alexis-king
View
215
Download
0
Embed Size (px)
Citation preview
.NET 2.0 and Visual .NET 2.0 and Visual Studio 2005Studio 2005
SigWin 2004SigWin 2004
OutlineOutline
Language enhancements in C#Language enhancements in C#– GenericsGenerics– Partial typesPartial types– Anonymous methodsAnonymous methods– Nullable typesNullable types
IDE featuresIDE features– Intellisense Intellisense – RefractoringRefractoring– Code snippetsCode snippets– Other awesome stuff!Other awesome stuff!
GenericsGenerics
MotivationMotivation
GenericsGenerics
One method:One method:public int AddSeconds(ArrayList myList) {public int AddSeconds(ArrayList myList) {
int total=0;int total=0;DateTime myDate;DateTime myDate;foreach (object myObj in myList) {foreach (object myObj in myList) {
myDate=(DateTime) myObj;myDate=(DateTime) myObj;total+=myDate.Second;total+=myDate.Second;
}}return total;return total;
}}
GenericsGenerics
Other method is to derive your Other method is to derive your own collection class. Namespace own collection class. Namespace is now cluttered with many is now cluttered with many strongly typed collectionsstrongly typed collections
Answer to problem: GENERICS!!!!!Answer to problem: GENERICS!!!!!
Generics: ExampleGenerics: Example
System.Collections.Generic:System.Collections.Generic:
private System.Collections.Generic.List<DateTime> private System.Collections.Generic.List<DateTime> myList;myList;
private Dictionary<string, Stack<DateTime>> private Dictionary<string, Stack<DateTime>> myList;myList;
Generics: old exampleGenerics: old example
public int AddSeconds(List<DateTime> myList) { int total = 0; foreach (DateTime myDate in myList) total += myDate.Second; return total; }
Partial typesPartial types
Easy way to separate Easy way to separate automatically generated code automatically generated code from your own:from your own:
public partial class myClass {}public partial class myClass {}
public partial class myClass {}public partial class myClass {}
Anonymous methodsAnonymous methods
Review of delegatesReview of delegates Anonymous delegate=delegate Anonymous delegate=delegate
without a function name, just without a function name, just codecode
Anonymous method Anonymous method example: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 typesNullable types
MotivationMotivation Syntax: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 IDEVisual Studio 2005 IDE
Demo!Demo!