14 generics and iterators

21
Generics & Iterators [email protected] Programming in C#

Upload: tuan-ngo

Post on 26-Aug-2014

746 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 14   generics and iterators

Generics & Iterators

[email protected]

Programming in C#

Page 2: 14   generics and iterators

Generics

Page 3: 14   generics and iterators

What is generics?

Page 4: 14   generics and iterators

What is generics? ensure type-safety the compiler will validate types while compiling, and throw an error if you try to assign the wrong type to a variable.

Page 5: 14   generics and iterators
Page 6: 14   generics and iterators

Benefits No Casting, and Boxing Increased Performance Ensured strongly-typed Model Reduced run-time errors

Page 7: 14   generics and iterators

Namespace for Generics System.Collection.Generic

Page 8: 14   generics and iterators

Namespace for Generics

Page 9: 14   generics and iterators

Implementation https://gist.github.com/2499823

Page 10: 14   generics and iterators

Constraints https://gist.github.com/2505556

Page 11: 14   generics and iterators

Inheriting generic classes

Page 12: 14   generics and iterators

Generic Methods virtual override abstract https://gist.github.com/2507425

Page 13: 14   generics and iterators

Generic Interfaces https://gist.github.com/2506990

Page 14: 14   generics and iterators

Generic Interface Constraints https://gist.github.com/2507482

Page 15: 14   generics and iterators

Question? https://gist.github.com/2507914

Page 16: 14   generics and iterators

Iterators

Page 17: 14   generics and iterators

Iterators is a way of navigating through the values in a collection. specify the way values are generated when the foreach statement accesses the elements within a collection.

Page 18: 14   generics and iterators

Benefits Perform Simplified Iteration Return Infinite values Reduce Complexity Save Memory

Page 19: 14   generics and iterators

Implementation https://gist.github.com/2507655

Page 20: 14   generics and iterators

Question? What is the difference between IEnumerator and IEnumerable?

Page 21: 14   generics and iterators

Question? What is the difference between IEnumerator and IEnumerable?

IEnumerable public IEnumerator GetEnumerator(); IEnumerator public object Current; public void Reset(); public bool MoveNext();