09 advanced c#

2,109 views

Published on

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,109
On SlideShare
0
From Embeds
0
Number of Embeds
1,664
Actions
Shares
0
Downloads
15
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

09 advanced c#

  1. 1. Advanced C#
  2. 2. Delegates • We can use interfaces instead of delegates. • Delegates – we need it to separate implementation and interface.
  3. 3. Anonymous function We don’t need to set name for function each time.
  4. 4. Lambda + Closures • Lambda – anonymous function with short syntax. • Closure - the function captures variables from the scope.
  5. 5. Problem
  6. 6. Solving- Iterators & foreach loop
  7. 7. Iterator pattern
  8. 8. IEnumerable<T> • IEnumerable<T> requires only one method to be implemented – IEnumerator<T> GetEnumerator() • Do not modify collection in the iteration process. • Remember that IEnumerables are lazy
  9. 9. IEnumerator<T> • Current returns the same object until MoveNext is called. MoveNext sets Current to the next element. • Initially, the enumerator is positioned before the first element in the collection. • If MoveNext() == false – Current is undefined. • You cannot set Current to the first element of the collection again; you must create a new enumerator instance instead. http://msdn.microsoft.com/ru-ru/library/s793z9y2(v=vs.110).aspx
  10. 10. Usage
  11. 11. Foreach loop • The foreach statement repeats a group of embedded statements for each element in an array or an object collection that implements the IEnumerable<T>
  12. 12. Yield • Method should returns IEnumerable<T> • Yield return one value and do MoveNext() = true • Yield break do MoveNext() = false
  13. 13. LINQ • LINQ - Language-Integrated Query • Extensions methods was implemented for LINQ
  14. 14. What we can to do with linq? - Filter/Transform/Aggregate/Generate data
  15. 15. LINQ and LINQ extensions
  16. 16. Recursion Recursion – see recursion Why we need it? - Tree traversing - Working with Linked Lists - etc…
  17. 17. Sum up • Use LINQ and LINQ extension methods – to declaratively specify what you want – to simplify your code – to generalize your code – to create complex abstractions from simple ones • Remember that IEnumerables are lazy • Use delegates to separate implementation and interface

×