Lecture 8 Set and Dictionary Sandy Ardianto & Erick Pranata © Sekolah Tinggi Teknik Surabaya 1
» Collections in.Net » Set » Dictionary » Exercises 2 © Sekolah Tinggi Teknik Surabaya
3
» Stacks and Queues are collections » A collection class can belong to one of two broad categories ˃ Nongeneric Collections: System.Collections and System.Collections.Spesialized ˃ Generic Collections: System.Collections.Generic 4 © Sekolah Tinggi Teknik Surabaya
5
6
7
8
» Poorly performing code ˃Lots of conversion » Not type safe ˃Any kind of data may be contained in a collection 9 © Sekolah Tinggi Teknik Surabaya
10 © Sekolah Tinggi Teknik Surabaya
11 © Sekolah Tinggi Teknik Surabaya
12 © Sekolah Tinggi Teknik Surabaya ICollection IList Stack Queue LinkedList ISet HashSet SortedSet IDictionary Dictionary SortedDictionary SortedList
© Sekolah Tinggi Teknik Surabaya 13
» A collection of distinct objects A intersects B 14 © Sekolah Tinggi Teknik Surabaya
» Count 15 © Sekolah Tinggi Teknik Surabaya
» Add » Clear » Contains » Remove 16 © Sekolah Tinggi Teknik Surabaya
» ExceptWith ˃Removes all elements in the specified collection from the current set. » IntersectWith ˃Modifies the current set so that it contains only elements that are also in a specified collection. » UnionWith ˃Modifies the current set so that it contains all elements that are present in either the current set or the specified collection. 17 © Sekolah Tinggi Teknik Surabaya
» IsSubsetOf ˃Determines whether a set is a subset of a specified collection. » IsSupersetOf ˃Determines whether the current set is a superset of a specified collection. » Overlaps ˃Determines whether the current set overlaps with the specified collection. » SetEquals ˃Determines whether the current set and the specified collection contain the same elements. 18 © Sekolah Tinggi Teknik Surabaya
» HashSet » SortedSet ˃Store objects in ascending order 19 © Sekolah Tinggi Teknik Surabaya
20
» A collection of key and value pairs. » Known as associative array. 21 © Sekolah Tinggi Teknik Surabaya
» Count » Item ˃Gets or sets the element with the specified key. » Keys ˃Gets an ICollection containing the keys of the IDictionary.ICollection » Values ˃Gets an ICollection containing the values in the IDictionary.ICollection 22 © Sekolah Tinggi Teknik Surabaya
» Add(Tkey, TValue) ˃Adds an element with the provided key and value to the IDictionary. » Clear » Contains » ContainsKey » Remove(Tkey) ˃Removes the element with the specified key from the IDictionary. » TryGetValue ˃Gets the value associated with the specified key. 23 © Sekolah Tinggi Teknik Surabaya
» Dictionary » SortedDictionary » SortedList 24 © Sekolah Tinggi Teknik Surabaya
25
Suatu sekolah gemar mendata nama, olahraga favorit dan tinggi setiap siswa yang baru masuk ke sekolah tersebut agar sekolah tersebut dapat memperoleh informasi mengenai tingkat minat siswa akan tren olahraga tertentu. Sejauh ini, hipotesis yang dikemukakan oleh Kesiswaan mengatakan bahwa Basket, Sepak Bola, dan Renang adalah olahraga yang sedang ngetren, sedangkan olah raga lain tidak termasuk hitungan. Anda diminta untuk membuat program yang memiliki fitur: » Input data siswa. » Laporan, berupa daftar nama yang diurutkan berdasarkan tinggi badan, descending, yaitu: ˃Laporan peminat Basket dan Sepak Bola. ˃Laporan peminat Basket, Sepak Bola, dan Renang. ˃Laporan peminat Basket atau Renang. ˃Laporan siswa yang hanya minat pada Sepak Bola. ˃Laporan siswa yang tidak memiliki minat terhadap ketiga olahraga tersebut. 26 © Sekolah Tinggi Teknik Surabaya
Read a text, then display word count for every word in the text. Leave out special characters and whitespaces 27 © Sekolah Tinggi Teknik Surabaya
» Andrew Troelsen, Pro C# and The.Net 4.5 Framework (Sixth Edition), Apress, 2012 » Set (mathematics), ematics) ematics) » System.Collections.Generic Namespace, us/library/System.Collections.Generic(v =vs.110).aspx us/library/System.Collections.Generic(v =vs.110).aspx 28 © Sekolah Tinggi Teknik Surabaya