SlideShare a Scribd company logo
Advanced C#
Delegates
• We can use interfaces instead of delegates.
• Delegates – we need it to separate
implementation and interface.
Anonymous function
We don’t need to set name for function each
time.
Lambda + Closures
• Lambda – anonymous function with short
syntax.
• Closure - the function captures variables from
the scope.
Problem
Solving- Iterators & foreach loop
Iterator pattern
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
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
Usage
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>
Yield
• Method should returns IEnumerable<T>
• Yield return one value and do MoveNext() =
true
• Yield break do MoveNext() = false
LINQ
• LINQ - Language-Integrated Query
• Extensions methods was implemented for
LINQ
What we can to do with linq?
- Filter/Transform/Aggregate/Generate data
LINQ and LINQ extensions
Recursion
Recursion – see recursion
Why we need it?
- Tree traversing
- Working with Linked Lists
- etc…
09 advanced c#
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

More Related Content

PPT
My first experience with lambda expressions in java
PPTX
Operating system
PDF
Beyond Mere Actors
PPSX
Java 8 – completion stage
ODP
Demystifying Eta Expansion
PPT
Intro To Scala
PPTX
Lec 2 algorithms efficiency complexity
PPTX
Iterable, iterator, generator by gaurav khurana
My first experience with lambda expressions in java
Operating system
Beyond Mere Actors
Java 8 – completion stage
Demystifying Eta Expansion
Intro To Scala
Lec 2 algorithms efficiency complexity
Iterable, iterator, generator by gaurav khurana

What's hot (18)

PPTX
Handling inputs via scanner class
PPTX
Matlab m files and scripts
PPTX
Inline function in C++
DOCX
PPT
Presentation mcrl2
PPTX
INLINE FUNCTION IN C++
PPTX
PPTX
PDF
C tour Unix
DOCX
lab stack and queue.docx
PPTX
Returning Data
PDF
Functions and tasks in verilog
PPTX
Introduction to Matlab Scripts
PDF
Valgrind
PPTX
Operators loops conditional and statements
PDF
Page Rank Algorithm
PPTX
Java 8 streams
PDF
Functions
Handling inputs via scanner class
Matlab m files and scripts
Inline function in C++
Presentation mcrl2
INLINE FUNCTION IN C++
C tour Unix
lab stack and queue.docx
Returning Data
Functions and tasks in verilog
Introduction to Matlab Scripts
Valgrind
Operators loops conditional and statements
Page Rank Algorithm
Java 8 streams
Functions
Ad

Viewers also liked (20)

PPTX
08 Exceptions and AOP
PPTX
PPTX
NoSQL basics
PPTX
Sql 04n edited
PPTX
12 Architecture
PPTX
Code Practices
PPTX
14 Patterns pt2
PPTX
Mvvw patterns
PPTX
SQL Grouping, Joins
PPTX
sql introduction
PPTX
Advanced C++ concepts
PPTX
11 web services
PDF
C++ Basics
PPTX
tsql
PPTX
#2 integration + ui tests
PPTX
SQL: Indexes, Select operator
PPTX
Design patterns
PPTX
Data Structures
PPTX
Unit1 summary
PPTX
#4 code quality
08 Exceptions and AOP
NoSQL basics
Sql 04n edited
12 Architecture
Code Practices
14 Patterns pt2
Mvvw patterns
SQL Grouping, Joins
sql introduction
Advanced C++ concepts
11 web services
C++ Basics
tsql
#2 integration + ui tests
SQL: Indexes, Select operator
Design patterns
Data Structures
Unit1 summary
#4 code quality
Ad

Similar to 09 advanced c# (20)

PPTX
Linq and lambda
ODP
Can't Dance The Lambda
PDF
New c sharp3_features_(linq)_part_iii
PPT
Of Lambdas and LINQ
PPTX
Announcemet_CCCSharp_07_Enumeration.pptx
PPT
C# programming
PPTX
Linq Introduction
PPT
Understanding linq
PPT
Testing for share
ODP
New c sharp3_features_(linq)_part_iv
PPTX
Evolve Your Code
PPTX
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
PDF
Dotnet programming concepts difference faqs- 2
PPT
PDF
C# 3.0 and 4.0
PPT
C#3.0 & Vb 9.0 New Features
PDF
Csharp_Chap13
PPTX
Parallel and Async Programming With C#
Linq and lambda
Can't Dance The Lambda
New c sharp3_features_(linq)_part_iii
Of Lambdas and LINQ
Announcemet_CCCSharp_07_Enumeration.pptx
C# programming
Linq Introduction
Understanding linq
Testing for share
New c sharp3_features_(linq)_part_iv
Evolve Your Code
Lowering in C#: What really happens with your code?, from NDC Oslo 2019
Dotnet programming concepts difference faqs- 2
C# 3.0 and 4.0
C#3.0 & Vb 9.0 New Features
Csharp_Chap13
Parallel and Async Programming With C#

More from eleksdev (20)

PPTX
Lecture android best practices
PPTX
Communication in android
PPTX
Hello android world
PPTX
Angular. presentation
PPTX
Android location and sensors API
PPTX
Lecture java basics
PPTX
Frontend basics
PPTX
Advanced styles
PPTX
Css animation, html5 api
PPTX
Improving rpc bkp
PPTX
G rpc lection1_theory_bkp2
PPTX
G rpc lection1
PPTX
Windows service
PPTX
PPTX
PPTX
Aspnet core
PPTX
Web service lecture
PPTX
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
PPTX
SDLC. QA Role
PPTX
SDLC. UX Role
Lecture android best practices
Communication in android
Hello android world
Angular. presentation
Android location and sensors API
Lecture java basics
Frontend basics
Advanced styles
Css animation, html5 api
Improving rpc bkp
G rpc lection1_theory_bkp2
G rpc lection1
Windows service
Aspnet core
Web service lecture
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
SDLC. QA Role
SDLC. UX Role

Recently uploaded (20)

PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Big Data Technologies - Introduction.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
20250228 LYD VKU AI Blended-Learning.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MYSQL Presentation for SQL database connectivity
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Network Security Unit 5.pdf for BCA BBA.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Building Integrated photovoltaic BIPV_UPV.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Big Data Technologies - Introduction.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

09 advanced c#

  • 2. Delegates • We can use interfaces instead of delegates. • Delegates – we need it to separate implementation and interface.
  • 3. Anonymous function We don’t need to set name for function each time.
  • 4. Lambda + Closures • Lambda – anonymous function with short syntax. • Closure - the function captures variables from the scope.
  • 6. Solving- Iterators & foreach loop
  • 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. 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. Usage
  • 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. Yield • Method should returns IEnumerable<T> • Yield return one value and do MoveNext() = true • Yield break do MoveNext() = false
  • 13. LINQ • LINQ - Language-Integrated Query • Extensions methods was implemented for LINQ
  • 14. What we can to do with linq? - Filter/Transform/Aggregate/Generate data
  • 15. LINQ and LINQ extensions
  • 16. Recursion Recursion – see recursion Why we need it? - Tree traversing - Working with Linked Lists - etc…
  • 18. 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