Download presentation
Presentation is loading. Please wait.
1
New Features in C# 2.0 Sergey Baidachni MCT, MCSD, MCDBA
2
C# ver. 2.0 Generics Iterators Partial types Anonymous method
3
Generics Array of object? What is it? How to create Generics
4
Array of object? Boxing and Unboxing ArrayList list=new ArrayList(); list.Add(4); list[0]=(int)list[0]+1; Explicit conversion int j; j=(int)list[0]; //unboxing Problem with performance and exceptions
5
Generics (What is it?) Templates in C++ No problem with performance List list=new List[int](); list.add(2); list.add(“table”); //compilation error No problem with conversion int j; j=list[0];
6
How create Generics (base syntaxes) Please use any name for your type class MyClass { private ItemType item; } Limitation: You can use only methods inherited from object
7
Generics (extensions) Use Where in order to extend your possibilities Class MyClass where T1: IMyInterface where T2: IComparable {…..} Interfaces public interface IMyInterface { void WhatIsIt(T i); }
8
Iterators Enumerators vs. Iterators yield keyword public IEnumerator GetEnumerator() { for(int i = 1;i< 5;i++) { yield return i; if(i > 2) yield break; } Benifits
9
Partial Types One class – many files? partial keyword //first file (MyClass_1.cs) public partial class MyClass { private int nCount;..... } //second file (MyClass_2.cs) public partial class MyClass { private bool isPresent..... }
10
Anonymous method Too lazy to write a separate method? There’s no need to. Button b=new Button(); b.Click+= new Button.ClickEventHandler(object s,EventArgs e) { Console.WriteLine(“Hello”); }; You can use local variable new? Who needs it?
11
Books .NET Framework: Secret tips on Windows Applications Creation by Sergey Baidachni .NET Framework: Secret tips on Web- application creation by Sergey Baidachni (coming up soon)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.