SlideShare a Scribd company logo
eleks.comeleks.com
Advanced C#. Part 1
Collections. Generics.
Algorithms Efficiency. Sorting algorithms.
System.Collections*
* - залишились в минулому після виходу .NET 2.0
• Колекція динамічно змінного розміруArrayList
• Колекція пар “ключ/значення”, організована на хеші ключаHashTable
• LIFO стек об’єктів. Реалізує методи Push(), Pop(), Peek()Stack
• Черга об’єктів, працююча за принципом FIFO. Enqueue(),
Dequeue(), Peek()Queue
• Колекція пар “ключ/значення”, відсортованих по ключуSortedList
Основні інтерфейси колекцій
IList
-Count
-GetEnumerator()
-Add(),Remove()
-Clear()
…
IEnumerator
-Current
-MoveNext()
-Reset()
IDictionary
-Keys
-Values
-GetEnumerator()
-Add(), Remove()
…
IEnumerable
-GetEnumerator()
ICloneable
-Clone()
ICollection
-Count
-GetEnumerator()
…
Дженеріки (Generics)
Класи
Інтерфейси
Структури
Методи
System.Collections.Generics
Узагальнені колекції Інтерфейси
• List<T>
• Dictionary<TKey, TValue>
• Queue<T>
• SortedDictionary<T>
• Hashset<T>
• SortedSet<T>
• KeyValuePair<T>
• Stack<T>
…
• IEnumerable<T>
• IDictionary<TKey, TValue>
• ICollection<T>
• IList<T>
• IEnumerator<T>
• IComparer<T>
• ISet<T>
• IReadOnlyList<T>
…
eleks.com
Демонстрація 1
• Робота з колекціями
• Реалізація власної колекції, унаслідуваної від IList<T>
Foreach
Yield
• Ключове слово yield додане в C# 2.0 для зручного створення ітераторів
• Використовується для повернення значення об’єкту енумератора або сигналу
про завершення ітерації. Може бути таких типів:
yield return [value];
yield break;
• yield return повертає один елемент з колекції і зміщує позицію до наступного
елементу. yield break зупиняє ітерування
eleks.com
Демонстрація 2
• Ітератор для повернення чисел Фібоначчі, менших N
Індексатори
Null і Nullable<T>
Типи, що допускають null:
• Всі reference-типи
• Nullable<T>, де T – value-тип
Характеристики Nullable-типів
o Властивості HasValue і Value – для перевірки на наявність значення в
nullable і отримання доступу до нього
o T? – скорочений запис для Nullable<T>
o ?? та ?. – синтаксичний цукор для перевірок на null
o Вкладенні nullable-типи не дозволені (Nullable<Nullable<T>>)
Класифікація алгоритмів за парадигмами
• Divide and conquer
• Dynamic programming
• The greedy method
• Linear programming
• Reduction (transform and conquer)
• Using graphs
• The probabilistic and heuristic paradigm
• Neural networks
Оцінка складності алгоритмів
• За часом та пам’яттю
• Big-O нотація (нотація Ландау)
Опис Порядок росту Приклад
Константний 1 Додавання двох чисел
Логарифмічний logN Двійковий пошук
Лінійний N Пошук максимума
Лінійно-логарифмічний NlogN Divide and conquer (сортування злиттям)
Квадратичний/Кубічний/... N2/N3/… Подвійні/потрійні/... повні цикли
Експоненціальний 2N Перевірка всіх підмножин
Поширені алгоритми сортування
Bubble Sort
(5 1 4 2 8) (1 5 4 2 8)
(1 5 4 2 8) (1 4 5 2 8)
(1 4 5 2 8) (1 4 2 5 8)
(1 4 2 5 8) (1 4 2 5 8)
(1 4 2 5 8) (1 4 2 5 8)
(1 4 2 5 8) (1 2 4 5 8)
(1 2 4 5 8) (1 2 4 5 8)
(1 2 4 5 8) (1 2 4 5 8)
Selection Sort
3 7 4 9 5 2 6 1
1 3 7 4 9 5 2 6
1 2 3 7 4 9 5 6
1 2 3 7 4 9 5 6
1 2 3 4 7 9 5 6
1 2 3 4 5 7 9 6
1 2 3 4 5 6 7 9
Insertion Sort
3 7 4 9 5 2 6 1
3 7 4 9 5 2 6 1
3 7 4 9 5 2 6 1
3 4 7 9 5 2 6 1
3 4 7 9 5 2 6 1
3 4 5 7 9 2 6 1
2 3 4 5 7 9 6 1
2 3 4 5 6 7 9 1
1 2 3 4 5 6 7 9
Merge Sort
Quick Sort
eleks.com
Практичне завдання
Рекомендована література
1. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest,
and Clifford Stein “Introduction to Algorithms”
2. D. Knuth “The art of computer programming”
3. R. Sedgewick “Algorithms”
4. N. Wirth “Algorithms and Data Structures”
Ad

More Related Content

Viewers also liked (20)

#4 code quality
#4 code quality#4 code quality
#4 code quality
eleksdev
 
Code Practices
Code PracticesCode Practices
Code Practices
eleksdev
 
Advanced C#. Part 2
Advanced C#. Part 2Advanced C#. Part 2
Advanced C#. Part 2
eleksdev
 
If unit2 summary
If unit2 summaryIf unit2 summary
If unit2 summary
eleksdev
 
Advanced c sharp part 3
Advanced c sharp part 3Advanced c sharp part 3
Advanced c sharp part 3
eleksdev
 
SDLC. QA Role
SDLC. QA RoleSDLC. QA Role
SDLC. QA Role
eleksdev
 
SQL Grouping, Joins
SQL Grouping, JoinsSQL Grouping, Joins
SQL Grouping, Joins
eleksdev
 
tsql
tsqltsql
tsql
eleksdev
 
Web service lecture
Web service lectureWeb service lecture
Web service lecture
eleksdev
 
Design patterns
Design patternsDesign patterns
Design patterns
eleksdev
 
Rpc
RpcRpc
Rpc
eleksdev
 
Improving rpc bkp
Improving rpc bkpImproving rpc bkp
Improving rpc bkp
eleksdev
 
Version control
Version controlVersion control
Version control
eleksdev
 
SDLC. PM Role
SDLC. PM RoleSDLC. PM Role
SDLC. PM Role
eleksdev
 
Sql 04n edited
Sql 04n editedSql 04n edited
Sql 04n edited
eleksdev
 
#2 integration + ui tests
#2 integration + ui tests#2 integration + ui tests
#2 integration + ui tests
eleksdev
 
Unit1 summary
Unit1 summaryUnit1 summary
Unit1 summary
eleksdev
 
SQL: Indexes, Select operator
SQL: Indexes, Select operatorSQL: Indexes, Select operator
SQL: Indexes, Select operator
eleksdev
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
eleksdev
 
.NET Platform. C# Basics
.NET Platform. C# Basics.NET Platform. C# Basics
.NET Platform. C# Basics
eleksdev
 
#4 code quality
#4 code quality#4 code quality
#4 code quality
eleksdev
 
Code Practices
Code PracticesCode Practices
Code Practices
eleksdev
 
Advanced C#. Part 2
Advanced C#. Part 2Advanced C#. Part 2
Advanced C#. Part 2
eleksdev
 
If unit2 summary
If unit2 summaryIf unit2 summary
If unit2 summary
eleksdev
 
Advanced c sharp part 3
Advanced c sharp part 3Advanced c sharp part 3
Advanced c sharp part 3
eleksdev
 
SDLC. QA Role
SDLC. QA RoleSDLC. QA Role
SDLC. QA Role
eleksdev
 
SQL Grouping, Joins
SQL Grouping, JoinsSQL Grouping, Joins
SQL Grouping, Joins
eleksdev
 
Web service lecture
Web service lectureWeb service lecture
Web service lecture
eleksdev
 
Design patterns
Design patternsDesign patterns
Design patterns
eleksdev
 
Improving rpc bkp
Improving rpc bkpImproving rpc bkp
Improving rpc bkp
eleksdev
 
Version control
Version controlVersion control
Version control
eleksdev
 
SDLC. PM Role
SDLC. PM RoleSDLC. PM Role
SDLC. PM Role
eleksdev
 
Sql 04n edited
Sql 04n editedSql 04n edited
Sql 04n edited
eleksdev
 
#2 integration + ui tests
#2 integration + ui tests#2 integration + ui tests
#2 integration + ui tests
eleksdev
 
Unit1 summary
Unit1 summaryUnit1 summary
Unit1 summary
eleksdev
 
SQL: Indexes, Select operator
SQL: Indexes, Select operatorSQL: Indexes, Select operator
SQL: Indexes, Select operator
eleksdev
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
eleksdev
 
.NET Platform. C# Basics
.NET Platform. C# Basics.NET Platform. C# Basics
.NET Platform. C# Basics
eleksdev
 

More from eleksdev (19)

Lecture android best practices
Lecture   android best practicesLecture   android best practices
Lecture android best practices
eleksdev
 
Communication in android
Communication in androidCommunication in android
Communication in android
eleksdev
 
Hello android world
Hello android worldHello android world
Hello android world
eleksdev
 
Angular. presentation
Angular. presentationAngular. presentation
Angular. presentation
eleksdev
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors API
eleksdev
 
Lecture java basics
Lecture   java basicsLecture   java basics
Lecture java basics
eleksdev
 
Frontend basics
Frontend basicsFrontend basics
Frontend basics
eleksdev
 
Advanced styles
Advanced stylesAdvanced styles
Advanced styles
eleksdev
 
Css animation, html5 api
Css animation, html5 apiCss animation, html5 api
Css animation, html5 api
eleksdev
 
G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2
eleksdev
 
G rpc lection1
G rpc lection1G rpc lection1
G rpc lection1
eleksdev
 
Windows service
Windows serviceWindows service
Windows service
eleksdev
 
DAL
DALDAL
DAL
eleksdev
 
Aspnet core
Aspnet coreAspnet core
Aspnet core
eleksdev
 
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
eleksdev
 
SDLC. UX Role
SDLC. UX RoleSDLC. UX Role
SDLC. UX Role
eleksdev
 
SDLC. BA Role
SDLC. BA RoleSDLC. BA Role
SDLC. BA Role
eleksdev
 
NoSQL basics
NoSQL basicsNoSQL basics
NoSQL basics
eleksdev
 
sql introduction
sql introductionsql introduction
sql introduction
eleksdev
 
Lecture android best practices
Lecture   android best practicesLecture   android best practices
Lecture android best practices
eleksdev
 
Communication in android
Communication in androidCommunication in android
Communication in android
eleksdev
 
Hello android world
Hello android worldHello android world
Hello android world
eleksdev
 
Angular. presentation
Angular. presentationAngular. presentation
Angular. presentation
eleksdev
 
Android location and sensors API
Android location and sensors APIAndroid location and sensors API
Android location and sensors API
eleksdev
 
Lecture java basics
Lecture   java basicsLecture   java basics
Lecture java basics
eleksdev
 
Frontend basics
Frontend basicsFrontend basics
Frontend basics
eleksdev
 
Advanced styles
Advanced stylesAdvanced styles
Advanced styles
eleksdev
 
Css animation, html5 api
Css animation, html5 apiCss animation, html5 api
Css animation, html5 api
eleksdev
 
G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2G rpc lection1_theory_bkp2
G rpc lection1_theory_bkp2
eleksdev
 
G rpc lection1
G rpc lection1G rpc lection1
G rpc lection1
eleksdev
 
Windows service
Windows serviceWindows service
Windows service
eleksdev
 
Aspnet core
Aspnet coreAspnet core
Aspnet core
eleksdev
 
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
Continuous Delivery concept overview. Continuous Integration Systems. DevOps ...
eleksdev
 
SDLC. UX Role
SDLC. UX RoleSDLC. UX Role
SDLC. UX Role
eleksdev
 
SDLC. BA Role
SDLC. BA RoleSDLC. BA Role
SDLC. BA Role
eleksdev
 
NoSQL basics
NoSQL basicsNoSQL basics
NoSQL basics
eleksdev
 
sql introduction
sql introductionsql introduction
sql introduction
eleksdev
 
Ad

Advanced C#. Part 1

Editor's Notes

  • #10: private static IEnumerable<int> GetFibonacciNumbers(int maxValue) { int previous = 0; int current = 1; while (true) { int next = current + previous; if (next <= maxValue) { previous = current; current = next; yield return next; } else { yield break; } } }
  翻译: