Professional Documents
Culture Documents
Advanced C#
Module Objectives
1. Boxing/Unboxing
2. Generics
3. Collection
4. Framework Interfaces
5. Manipulating Strings
Boxing and Unboxing
• Boxing refers to implicit conversion of a value type into an
object type, or to any interface that it implements, e.g., int to
IComparable<int>.
• Further, the conversion of an underlying value type to a
nullable type is also known as boxing.
Unboxing
1. System.Collections
2. System.Collections.Generic
3. System.Collections.Concurrent
System.Collections
ArrayList
• ArrayList is a non-generic type of collection in C#. It can
contain elements of any data types. It is similar to an array,
except that it grows automatically as you add items in it.
ArrayList
Hashtable
• Hashtable stores each element of a collection in a pair of
key/values.
Hashtable
Queue
• Queue represents a first-in, first out collection of object. It
is used when you need a first-in, first-out access of items.
When you add an item in the list, it is called enqueue, and
when you remove an item, it is called dequeue.
Queue
Stack
• Stack represents a last-in, first out collection of object. It is
used when you need a last-in, first-out access to items.
When you add an item in the list, it is called pushing the
item and when you remove it, it is called popping the item.
Stack
System.Collections.Generics
• System.Collections.Generics is a namespace which contains
classes and interfaces to manage a strongly-typed collection.
List<T>
• List<T> class in C# represents a strongly typed list of
objects. List<T> provides functionality to create a list of
objects, find list items, sort list, search list, and manipulate
list items. In List<T>, T is the type of objects.
List<T>
Dictionary<TKey, TValue>
• It’s a type-safe collection of key/value pairs. Each key in
dictionary must be unique and can store multiple values
against the same key. Dictionary<TKey, TValue> is much
faster than Hashtable.
Dictionary<TKey, TValue>
Queue<T>
• Queue<T> is a type-safe class. It stores and retrieves data in
FIFO (First In, First Out) order. In other words, it manages a
collection of data on a first come, first served basis. It is
much faster than Queue.
Queue<T>
Stack<T>
• Stack<T> is a class. It stores and retrieves elements in LIFO
(Last In, First Out) order. Elements pushed at the end will
pop up first, for example, a pile of plates. It is much faster
than Stack.
Stack<T>
Working with Strings
• Strings are one of most frequent use data types in C#.
Strings in C# are immutable means that once a string is
created, it cannot be changed. No characters can be added
or removed from it, nor can its length be changed.
• To solve this problem, C# introduced StringBuilder.
StringBuilder is a dynamic object that allows you to expand
the number of characters in the string.
StringBuilder
StringReader
• StringReader is a class of System.IO used to read lines from a
string. With StringReader, we can read a character with Read or
ReadAsync method, and an entire string with ReadToEnd or
ReadToEndAsync method. This type helps to access string data
through a stream-oriented interface.
StringWriter
• StringWriter is a class of System.IO. It is used to write to a
StringBuilder class. With StringWriter, we can write a
character/string with Write or WriteAsync method, and an entire
string line with WriteLine or WriteLineAsync method. It’s an
efficient way of using StringBuilder with StringWriter to
manipulate string.
PRG521
Main | CH4
Heading | Subheading
The End
2 0 2 32 0C2T0U CTTr U
a i nTirnagi nSi nogl u St ioolnust i o|n sA l |l RAi gl l hRt si gRhet s eRr ev es edr v |e dc t u| t rcat iuntirnagi n. ai nc g
. z. a c . z a