80 likes | 239 Views
Generics. Samar Samy FCI-Helwan University Microsoft Student Partner – Microsoft Egypt . Microsoft Tech-Club Helwan Univ. – Technical Dept. What are Generics ??. - Generics are the most powerful feature of C# 2.0 . - Generics allow you to define type-safe data structures, .
E N D
Generics Samar Samy FCI-Helwan University Microsoft Student Partner – Microsoft Egypt . Microsoft Tech-Club Helwan Univ. – Technical Dept.
What are Generics ?? - Generics are the most powerful feature of C# 2.0. - Generics allow you to define type-safe data structures,
Before Generics : Using System.Collections; Stack s = new Stack(); s.Push(7); Int x = (int)s.pop();
With Generics: Using Sysytem.Collections.Generics; Stack <int> s = new Stack<int>(); s.Push(7); // no castInt x = s.pop
2 Benefits Of Generics 2 Benefits of Generics
Type Safe Using System.Collections; Stack s = new Stack(); s.Push(7); s.push(“seven”); object O = s.pop(); // Now what ????? Using System.Collections.Generics; Stack <int>s = new Stack<int>(); s.Push(7); //compile-time Errors.push(“seven”);
Performance: Boxing and Unboxing : If we wrote : int i = 123 ; Object o = i ; // Boxing int j=(int) o ; // unboxing
Thanks You can contact me at: eng_samar95@yahoo.com eng.samar_fci@yahoo.com Blog : http://samarsamy.wordpress.com/ Samar Samy FCI-Helwan University Microsoft Student Partner – Microsoft Egypt . Microsoft Tech-Club Helwan Univ. – Technical Dept.