Introduction

Chapter 18 是关于 IDE 的,不重要所以未收录。

Chapter 10: Collections

COLLECTION INTERFACES AND TYPES

INTERFACE DESCRIPTION
IEnumerable<T> The interface IEnumerable is required by the foreach statement. This interface defines the method GetEnumerator, which returns an enumerator that implements the IEnumerator interface.
ICollection<T> ICollection<T> is implemented by generic collection classes. With this you can get the number of items in the collection Count property), and copy the collection to an array (CopyTo method). You can also add and remove items from the collection (Add, Remove, Clear).
IList<T> The IList<T> interface is for lists where elements can be accessed from their position. This interface defines an indexer, as well as ways to insert or remove items from specific positions (Insert, RemoveAt methods). IList<T> derives from ICollection<T>.
ISet<T> This interface is implemented by sets. Sets allow combining different sets into a union, getting the intersection of two sets, and checking whether two sets overlap. ISet<T> derives from ICollection<T>.
IDictionary<TKey, TValue> The interface IDictionary<TKey, TValue> is implemented by generic collection classes that have a key and a value. With this interface all the keys and values can be accessed, items can be accessed with an indexer of type key, and items can be added or removed.
ILookup<TKey, TValue> Like the IDictionary<TKey, TValue> interface, lookups have keys and values. However, with lookups the collection can contain multiple values with one key.
IComparer<T> The interface IComparer<T> is implemented by a comparer and used to sort elements inside a collection with the Compare method.
IEqualityComparer<T> IEqualityComparer<T> is implemented by a comparer that can be used for keys in a dictionary. With this interface the objects can be compared for equality.

PERFORMANCE

COLLECTION|ADD|INSERT|REMOVE|ITEM|SORT|FIND

COLLECTION ADD INSERT REMOVE ITEM SORT FIND
List<T> O(1)O(1) or O(n)O(n) if the collection must be resized O(n)O(n) O(n)O(n) O(1)O(1) O(nlogn)O (n \log n) worst case O(n2)O(n ^ 2) O(n)O(n)
Stack<T> Push, O(1)O(1), or O(n)O(n) if the stack must be resized n/a Pop, O(1)O(1) n/a n/a n/a
Queue<T> Enqueue, O(1)O(1), or O(n)O(n) if the queue must be resized n/a Dequeue, O(1)O(1) n/a n/a n/a
HashSet<T> O(1)O(1) or O(n)O(n) if the set must be resized Add O(1)O(1) or O(n)O(n) O(1)O(1) n/a n/a n/a
SortedSet<T> O(1)O(1) or O(n)O(n) if the set must be resized Add O(1)O(1) or O(n)O(n) O(1)O(1) n/a n/a n/a
LinkedList<T> AddLast O(1)O(1) Add After O(1)O(1) O(1)O(1) n/a n/a O(n)O(n)
Dictionary<TKey, TValue> O(1)O(1) or O(n)O(n) n/a O(1)O(1) O(1)O(1) n/a n/a
SortedDictionary<TKey, TValue> O(logn)O(\log n) n/a O(logn)O(\log n) O(logn)O(\log n) n/a n/a
SortedList<TKey, TValue> O(n)O(n) for unsorted data, O(logn)O(\log n) for end of list, O(n)O(n) if resize is needed n/a O(n)O(n) O(logn)O(\log n) to read/write, O(logn)O(\log n) if the key is in the list, O(n)O(n) if the key is not in the list n/a n/a

Chapter 11: Special Collections

WORKING WITH BITS

高阶知识,以后再补

OBSERVABLE COLLECTIONS

高阶知识,以后再补

IMMUTABLE COLLECTIONS

高阶知识,以后再补

CONCURRENT COLLECTIONS

Chapter 12: Language Integrated Query

LINQ OVERVIEW

STANDARD QUERY OPERATORS

PARALLEL LINQ

EXPRESSION TREES

高阶知识,以后再补

LINQ PROVIDERS

Chapter 13: Functional Programming with C#

TUPLES

PATTERN MATCHING

Chapter 14: Errors and Exceptions

Chapter 15: Asynchronous Programming

ERROR HANDLING

Chapter 16: Reflection, Metadata, and Dynamic Programming

CUSTOM ATTRIBUTES

USING REFLECTION

THE DYNAMIC TYPE

Chapter 17: Managed and Unmanaged Memory

  • 此章涉及底层理论知识,建议看书。
  • 除 GC 部分外的高阶知识可以以后补。

MEMORY MANAGEMENT UNDER THE HOOD

STRONG AND WEAK REFERENCES

WORKING WITH UNMANAGED RESOURCES

UNSAFE CODE

REFERENCE SEMANTICS

SPAN

Chapter 3 includes creating reference types (classes) and value types (structs). Instances of classes are stored on the managed heap. The value of structs can be stored on the stack, or, when boxing is used, on the managed heap. Now we have another kind: a type that can have its value only on the stack but never on the heap, sometimes called ref-like types. Boxing is not possible with these types. Such a type is declared with the ref struct keyword. Using ref struct gives some additional behaviors and restrictions. The restrictions are the following:

  • They can't be added as array items.
  • They can't be used as generic type argument.
  • They can't be boxed.
  • They can't be static fields.
  • They can only be instance fields of ref-like types.

PLATFORM INVOKE