# MS 70-536.1
## Part 1. Developing applications that use types and collections
### 1.1 Manage data in a .NET Framework application by using the .NET Framework 2.0 system types.

Data types are separated into value types and reference types. Value types are either stack-allocated or allocated inline in a structure.
In cases where a value type needs to act like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type's value is copied into it. The wrapper is marked so that the system knows that it contains a value type. This process is known as boxing, and the reverse process is known as unboxing. Boxing and unboxing allow any type to be treated as an object.
In .Net and mono (nearly) everything is a Type. The key to finding out about types is the System.Type class. This class can be used to investigate a type. The quickest way to get hold of a type in c# is to use the typeof operator. This operator returns a System.Type object.

#### 1.1.1 Value types

We can investigate types using System>Type and some reflection.

#### 1.1.5 Exception classes

See: System.Exception
All exceptions derive from the System.Exception class. This class has three constructors to throw a new exception either the first or second constructor can be used. To throw a nested exception the third constructor is used. Each of the constructors is illustrated below.
In practice exceptions that are thrown should derive from System.Exception. It is bad practice to throw System.Exception directly.

#### 1.1.7 TypeForwardedToAttribute Class
### 1.2 Manage a group of associated data in a .NET Framework application by using collections.

Managing groups of data as a unit where each data item can be accessed is a common operation. The System.Collections namespace provides several different types for managing collections. The collections are related to one another by the fact that they implement IEnumrable and ICollection (Check this).
The three interfaces IList, ICollection and IDictionary are structured in the following way:
| ICollection : IEnumerable IList : ICollection, IEnumerable IDictionary : ICollection, IEnumerable | O-- IEnumerable ^ | O-- ICollection ^ | |--------|--------| | | O-- IDictionary O-- IList |
The main classes of System.Collections are as follows:
| ArrayList : IList BitArray : ICollection HashTable : IDictionary Queue : ICollection SortedList : IDictionary Stack : ICollection | ICollection - BitArray, Queue, Stack IList - ArrayList IDictionary - HashTable, SortedList |

##### ArrayList class

ArrayList implements a variable-size IList that uses an array of objects to store the elements. A ArrayList has a ArrayList.Capacity, which is the allocated length of the internal array. The total number of elements contained by a list is its ArrayList.Count. As elements are added to a list, its capacity is automatically increased as required by reallocating the internal array.

##### Collection interfaces

* ICollection interface and IList interface
* IComparer interface and IEqualityComparer interface
* IDictionary interface and IDictionaryEnumerator interface
* IEnumerable interface and IEnumerator interface

##### Hashtable class

A Hashtable represents a dictionary with a constant lookup time that contains entries of associated keys and values. The type of each entry in a Hashtable is DictionaryEntry. A statement that exposes each element in the collection is required to iterate over this type.

##### BitArray class

The System.Collections.BitArray implements a collection of boolean values. There are a number of different constructors for a BitArray. The BitArray( ) creates ... The methods of a BitArray allow a bitwise operation to be performed on the BitArray.
Compiling and running this example gives the following output:

##### Stack class

The stack is a collection supporting only the push, pop, and peek operations. The push method puts an object onto the end of the stack. The peek method returns the most recent object placed on the stack. The pop method removes the most recent object placed on the stack and returns it.

### 1.3 Improve type safety and application performance in a .NET Framework application by using generic collections

There is often a need to have a collection only store objects of a given type. For example an ArrayList might be used to store only strings.
However this is not type safe as at any point in the lifetime of the stringArray object an object that is not a string can added.
There is also the convenience of having to cast down the items retreived from the stringArray.
In earlier versions of c# the only way to have type safe collections was either to wrap an existing collection or derive from an existing collection.

##### Collection.Generic interfaces

* Generic IComparable interface (Refer System Namespace)
* Generic ICollection interface and Generic IList interface
* Generic IComparer interface and Generic IEqualityComparer interface
* Generic IDictionary interface
* Generic IEnumerable interface and Generic IEnumerator interface
* IHashCodeProvider interface

##### Generic Dictionary

* Generic Dictionary class and Generic Dictionary.Enumerator structure
* Generic Dictionary.KeyCollection class and Dictionary.KeyCollection.Enumerator structure
* Generic Dictionary.ValueCollection class and Dictionary.ValueCollection.Enumerator structure

##### Generic LinkedList

* Generic LinkedList class
* Generic LinkedList.Enumerator structure
* Generic LinkedListNode class

##### Generic Stack class and Generic Stack.Enumerator structure
### 1.4 Manage data in a .NET Framework application by using specialized collections.
##### Specialized String classes

* StringCollection class
* StringDictionary class
* StringEnumerator class

##### Specialized Dictionary

* HybridDictionary class
* IOrderedDictionary interface and OrderedDictionary class
* ListDictionary class

##### Named collections

* NameObjectCollectionBase class
* NameObjectCollectionBase.KeysCollection class
* NameValueCollection class

##### BitVector32 structure and BitVector32.Section structure
### 1.5 Implement .NET Framework interfaces to cause components to comply with standard contracts.
##### IFormattable interface
### 1.6 Control interactions between .NET Framework application components by using events and delegates.
##### Delegate class

A delegate is similar to a typed function pointer.
The ThermoStat class
A delegate allows the act of calling a method to be delegated to someone else.

##### Delegate class - test driven

In this section we'll explore delegates using unit tests. The first question we'll look at is when are delgates created?
A delegate is created when an method is added to the invocation list. The delegate is distroyed when there are no more methods in the invocation list.

##### EventArgs class

The EventArgs class is a base class for use in the pattern described in the next section. To pass arguments sub classes are derived from the EventArgs class.

##### EventHandler delegates

The EventHanlder is part of a pattern for handling events that is aimed at reducing the proliferation of different delegates. In this pattern there is one delegate, the EventHandler delegate.