Presentation is loading. Please wait.

Presentation is loading. Please wait.

Sets, Dictionaries SoftUni Team Technical Trainers Software University

Similar presentations


Presentation on theme: "Sets, Dictionaries SoftUni Team Technical Trainers Software University"— Presentation transcript:

1 Sets, Dictionaries SoftUni Team Technical Trainers Software University http://softuni.bg

2 Table of Contents 1.Dictionaries – Dictionary, SortedDictionary 2.Sets – HashSet, SortedSet 2

3 3 sli.do #4535 Questions

4 Sets HashSet and SortedSet 3 73 7 -3 5 46

5 5  A set keep unique elements  Provides methods for adding/removing/searching elements  Offers very fast performance  HashSet  The elements are randomly ordered  SortedSet  The elements are ordered incrementally Sets in C#

6 Pesho HashSet 6 HashSet – Add() Gosho Hash Function Alice

7 Pesho HashSet 7 HashSet – Remove() Gosho Hash Function Alice

8 Pesho SortedSet 8 SortedSet – Add() Gosho Alice

9 HashSet and SortedSet Exercises in class

10 Associative Arrays Dictionary иван гошо пешо 0845-346-356 2350-452-167 1255-377-131

11  Associative arrays are arrays indexed by keys  Not by the numbers 0, 1, 2, …  Hold a set of pairs Associative Arrays (Dictionaries)  Traditional array  Associative array 0 1 2 3 4 8-31240833 John Smith +1-555-8976 Lisa Smith +1-555-1234 Sam Doe +1-555-5030 key value key value 11

12 Dictionary – Add() 12 Dictionary Key Value Hash Function Pesho0881-123-987 Gosho0881-123-789 Alice0881-123-978

13 Dictionary – Remove() 13 Dictionary Key Value Hash Function Pesho 0881-123-987 Gosho0881-123-789 Alice0881-123-978

14 Pesho0881-123-987 SortedDictionary – Example 14 SortedDictionary Key Value Alice+359-899-55-592

15 15 Looping through dictionaries Gosho0881-456-987 Pesho0881-123-987 Dictionary Alice+359-899-55-592 KeyValuePair keyValuePair in For Each.Key.Value Alice+359-899-55-592 Pesho0881-123-987 0881-456-987 Gosho

16 Dictionary and SortedDictionary Dictionary and SortedDictionary  Have property Count – the number of key-value pairs  Keys – a set of unique keys  Values – a collection of all values  Basic operations – Add(), Remove(), Clear()  Boolean methods:  ContainsKey() – checks if a key is present in the dictionary  ContainsValue() – checks if a value is present in the dictionary  TryGetValue() – check if a key is present in the dictionary and ouputs the value, or returns the default value of the type. 16

17 Associative Arrays Exercises in class

18  The HashSet and SortedSet hold unique elements and are very fast  Dictionary is an associative array where a value is accessed by its key Summary 18

19 ? ? ? ? ? ? ? ? ? Sets, Dictionaries https://softuni.bg/courses/advanced-csharp

20 License  This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" licenseCreative Commons Attribution- NonCommercial-ShareAlike 4.0 International  Attribution: this work may contain portions from  "C# Fundamentals – Part 1" course by Telerik Academy under CC-BY-NC-SA licenseCC-BY-NC-SA  "C# Fundamentals – Part 2" course by Telerik Academy under CC-BY-NC-SA licenseCC-BY-NC-SA 20

21 Free Trainings @ Software University  Software University Foundation – softuni.orgsoftuni.org  Software University – High-Quality Education, Profession and Job for Software Developers  softuni.bg softuni.bg  Software University @ Facebook  facebook.com/SoftwareUniversity facebook.com/SoftwareUniversity  Software University @ YouTube  youtube.com/SoftwareUniversity youtube.com/SoftwareUniversity  Software University Forums – forum.softuni.bgforum.softuni.bg


Download ppt "Sets, Dictionaries SoftUni Team Technical Trainers Software University"

Similar presentations


Ads by Google