Download presentation
Presentation is loading. Please wait.
Published byAlexis King Modified over 9 years ago
1
.NET 2.0 and Visual Studio 2005 SigWin 2004
2
Outline Language enhancements in C# Language enhancements in C# –Generics –Partial types –Anonymous methods –Nullable types IDE features IDE features –Intellisense –Refractoring –Code snippets –Other awesome stuff!
3
Generics Motivation Motivation
4
Generics One method: 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; }
5
Generics Other method is to derive your own collection class. Namespace is now cluttered with many strongly typed collections Other method is to derive your own collection class. Namespace is now cluttered with many strongly typed collections Answer to problem: GENERICS!!!!! Answer to problem: GENERICS!!!!!
6
Generics: Example System.Collections.Generic: System.Collections.Generic: private System.Collections.Generic.List myList; private Dictionary > myList;
7
Generics: old example public int AddSeconds(List myList) { int total = 0; foreach (DateTime myDate in myList) total += myDate.Second; return total; }
8
Partial types Easy way to separate automatically generated code from your own: Easy way to separate automatically generated code from your own: public partial class myClass {}
9
Anonymous methods Review of delegates Review of delegates Anonymous delegate=delegate without a function name, just code Anonymous delegate=delegate without a function name, just code
10
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”); }
11
Nullable types Motivation Motivation 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);
12
Visual Studio 2005 IDE Demo! Demo!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.