C# Collections. Generic Collections презентация

C# Collections. Generic Collections
 SoftServe UniversityAgendaArray
 Array is a data structure that contains several variables ofArray. ExamplesArray. Examples
 Multidimensional arrays:
 	string [ , ] names = newArray. Benefits. Limitations
 Benefits of Arrays:
 Easy to use: arrays areSystem.Collections. ArrayList
 System.Collections namespace
 ArrayList, HashTable, SortedList, Queue, Stack:
 A collectionArrayList
 ArrayList is a special array that provides us with someArrayList servicesArrayList. Benefits and Limitation
 Benefits of ArrayList:
 Supports automatic resizing. 
Stack
 Stack: last-in-first-outQueue
 Queue: first-in-first-outHashtable
 Represents a collection of key/value pairs that are organized basedHashtable
 Limitations of Hashtable:
 Performance and speed: Hashtable objects are slowerSortedList
 Represents a collection of key/value pairs that are sorted bySortedList
 [SerializableAttribute] 
 [ComVisibleAttribute(true)] 
 public class SortedList : IDictionary,
 			Collections. Drawbacks
 No type checking enforcement at compile time
 Doesn’t preventSystem.Collections.Generic
 Open constructed types 
 Classes defined without a specific type
List<T>
 List generic class:
 		[SerializableAttribute] 
 		public class List<T> : IList<T>,List<T>
 Methods such as BinarySearch and Sort use an ordering comparerQuestions?



Слайды и текст этой презентации
Слайд 1
Описание слайда:
C# Collections. Generic Collections SoftServe University


Слайд 2
Описание слайда:
Agenda

Слайд 3
Описание слайда:
Array Array is a data structure that contains several variables of the same type. type [ ] arrayName; Array has the following properties: array can be Single-dimensional, Multidimensional or Jagged. The default value of numeric array elements are set to zero, and reference elements are set to null. Arrays are zero indexed: an array with n elements is indexed from 0 to n-1. Array elements can be of any type, including an array type. Array types are reference types derived from the abstract base type Array. It implements IEnumerable and IEnumerable<(Of <(T>)>), for using in foreach

Слайд 4
Описание слайда:
Array. Examples

Слайд 5
Описание слайда:
Array. Examples Multidimensional arrays: string [ , ] names = new string[5,4]; Array-of-arrays (jagged): byte [ ][ ] scores = new byte[ 5 ][ ]; for ( int i = 0; i < scores.Length; i++) { scores[i] = new byte[4]; } Three-dimensional rectangular array: int [ , , ] buttons = new int [ 4, 5, 3];

Слайд 6
Описание слайда:
Array. Benefits. Limitations Benefits of Arrays: Easy to use: arrays are used in almost every programming language Fast to change elements. Fast to move through elements: Because an array is stored continuously in memory, it's quick and easy to cycle through the elements one-by-one from start to finish in a loop. You can specify the type of the elements: When you create an array, you can define the datatype. Limitations of Arrays: Fixed size: Once you have created an array, it will not automatically items onto the end. Inserting elements mid-way into a filled array is difficult.

Слайд 7
Описание слайда:
System.Collections. ArrayList System.Collections namespace ArrayList, HashTable, SortedList, Queue, Stack: A collection can contain an unspecified number of members. Elements of a collection do not have to share the same datatype. An object's position in a collection can change whenever a change occurs in the whole, herefore, the position of a specific object in the collection can vary.

Слайд 8
Описание слайда:
ArrayList ArrayList is a special array that provides us with some functionality over and above that of the standard Array. We can dynamically resize it by simply adding and removing elements.

Слайд 9
Описание слайда:
ArrayList services

Слайд 10
Описание слайда:
ArrayList. Benefits and Limitation Benefits of ArrayList: Supports automatic resizing. Inserts elements: An ArrayList starts with a collection containing no elements. Flexibility when removing elements. Easy to use. Limitation of ArrayLists: There is one major limitation to an ArrayList: speed. The flexibility of an ArrayList comes at a cost, and since memory allocation is a very expensive business the fixed structure of the simple array makes it a lot faster to work with.

Слайд 11
Описание слайда:
Stack Stack: last-in-first-out

Слайд 12
Описание слайда:
Queue Queue: first-in-first-out

Слайд 13
Описание слайда:
Hashtable Represents a collection of key/value pairs that are organized based on the hash code of the key. The objects used as keys must override the GetHashCode method and the Equals method. Benefits of Hashtable: Non-numeric indexes allowed. Key can be numeric, textual, or even in form of a date. But can’t be null reference. Easy inserting elements. Easy removing elements. Fast lookup.

Слайд 14
Описание слайда:
Hashtable Limitations of Hashtable: Performance and speed: Hashtable objects are slower to update but faster to use in a look-up than ArrayList objects. Keys must be unique: An array automatically keeps the index values unique. In a Hastable we must monitor the key uniqueness. No useful sorting: The items in a Hashtable are sorted internally to make it easy to find objects very quickly. It's not done by keys or values, the items may as well not be sorted at all.

Слайд 15
Описание слайда:
SortedList Represents a collection of key/value pairs that are sorted by the keys Are accessible by key and by index. A SortedList object internally maintains two arrays to store the elements of the list Use the new keyword when creating the object. Each adding item is automatically inserted in the correct position in the list, according to a specific IComparer implementation .

Слайд 16
Описание слайда:
SortedList [SerializableAttribute] [ComVisibleAttribute(true)] public class SortedList : IDictionary, ICollection, IEnumerable, ICloneable {…}

Слайд 17
Описание слайда:
Collections. Drawbacks No type checking enforcement at compile time Doesn’t prevent adding unwanted types Can lead to difficult to troubleshoot issues Runtime errors! All items are stored as objects Must be cast going in and coming out Performance overhead of boxing and unboxing specific types

Слайд 18
Описание слайда:
System.Collections.Generic Open constructed types Classes defined without a specific type Type is specified when instantiated Provides type safety at compile time

Слайд 19
Описание слайда:
List<T> List generic class: [SerializableAttribute] public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, Ienumerable The List class is the generic equivalent of the ArrayList class. It implements the IList generic interface using an array whose size is dynamically increased as required. The List class uses both an equality comparer and an ordering comparer. Methods such as Contains, IndexOf, LastIndexOf, and Remove use an equality comparer for the list elements. If type T implements the IEquatable generic interface, then the equality comparer is the Equals method of that interface; otherwise, the default equality comparer is Object.Equals(Object).

Слайд 20
Описание слайда:
List<T> Methods such as BinarySearch and Sort use an ordering comparer for the list elements. The List is not guaranteed to be sorted. You must sort the List before performing operations (such as BinarySearch) that require the List to be sorted. Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based. List accepts a null reference as a valid value for reference types and allows duplicate elements.

Слайд 21
Описание слайда:

Слайд 22
Описание слайда:
Questions?


Скачать презентацию на тему C# Collections. Generic Collections можно ниже:

Похожие презентации