Masterofcode C-Collection
Masterofcode C-Collection
Namespace: System.Collections.Generic
Specifies the type of elements in the stack.
Assembly: System.Collections.dll
// Create a stack of strings
Stack<string> numbers = new Stack<string>();
Represents a strongly typed list of objects that can be accessed by index. Provides methods
// Add items to the stack
to search, sort, and manipulate lists.
numbers.Push("one");
// Create a list of parts.
numbers.Push("two");
List<Part> parts = new List<Part>();
// Add parts to the list.
Stack<T> Methods
parts.Add(new Part() { PartName = "crank arm", PartId = 1234 });
parts.Add(new Part() { PartName = "chain ring", PartIdMethod Usage
= 1334 }); Example
Stack<
parts.Add(new Part() { PartName = "regular seat", PartId = ‐1434Inserts
}) an object at numbers.Push("one");
; T>.P‐ the top of the
ush(T)
parts.Add(new Part() { PartName = "banana seat", PartId = 1444 Stack<
}); T>.
parts.Add(new Part() { PartName = "cassette", PartIdStack<
= 1534‐ Removes and
}); numbers.Pop();
T>.Pop
parts.Add(new Part() { PartName = "shift lever", PartId = 1634 returns
}); the object at
the top of the
List<T> Methods Stack<T>.
Stack<‐ Represents a first in, numbers.Push("one");
T>.P‐ first out (FIFO)
ush(T) collection of objects.
Stack<‐ The object at the top numbers.Peek();
T>.Peek of the Stack<T>.
Stack<‐ Determines whether stack2.Contains("fou
T>.Con‐ an element is in the r");
tains(T) Stack<T>.
Stack<‐ Removes all objects stack2.Clear();
T>.Clear from the Stack<T>.
cheatography.com/masterofcode/
C# Collection Cheat Sheet
by masterofcode via cheatography.com/140841/cs/30006/
For further information and examples visit this link Represents a collection of keys and values.
// Create a new dictionary of strings, with string keys.
System.Collections.Generic Classes Dictionary<string, string> openWith =
new Dictionary<string, string>();
openWith.Add("txt", "notepad.exe");
Dictionary<TKey,TValue> Methods
Class Description Method Usage Example
Dictionar‐ Represents a collection of key/value pairs that are Dictio‐ Adds the openWith.Add("txt", "notepad
y<T‐ organized based on the key. nar‐ specified .exe");
Key,TV‐ y<T‐ key and
alue> Key,TV‐ value to
List<T> Represents a list of objects that can be accessed by alu‐ the
index. Provides methods to search, sort, and modify e>.A‐ dictio‐
lists. dd‐ nary.
(TKey,
Queue<T> Represents a first in, first out (FIFO) collection of
TValue)
objects.
Dictio‐ Removes public bool Remove (TKey key);
SortedLis‐ Represents a collection of key/value pairs that are
nar‐ the value openWith.Remove("doc");
t<T‐ sorted by key based on the associated IComparer<T>
y<T‐ with the
Key,TV‐ implementation.
Key,TV‐ specified
alue>
alu‐ key from
Stack<T> Represents a last in, first out (LIFO) collection of
e>.R‐ the
objects.
emove Dictio‐
nary<T‐
Key,TV‐
alue>.
cheatography.com/masterofcode/
C# Collection Cheat Sheet
by masterofcode via cheatography.com/140841/cs/30006/
cheatography.com/masterofcode/