Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Collections;
Using System. Collections. Specialized;
 
Namespace ConsoleApplication1
{
Class Program
{
Static void Main (string [] args)
{
ArrayList myList = new ArrayList (20 );
MyList. Add (20); // boxed operation.
 
MyList. Add (1, 202 );
 
Int i1 = (int) myList [0]; // binning
 
Foreach (int item in myList)
{
Console. WriteLine (item); // This program is about ArrayList.
}
 
List <int> myListT = new List <int> (10 );
MyListT. Add (412); // No packing operation
 
Int i2 = myListT [0]; // it will not be split.
 
Foreach (int item in myListT)
{
Console. WriteLine (item );
}
// It is worth noting that if there are different types when values are included, but an error is reported when the foreach loop is used,
// You can avoid this situation by using generics. An error is reported during compilation.
 
 
}
Public class MyOK // below are some examples of generics
{
Public delegate void EventHandler <TEventArgs> (object sender, TEventArgs e );
 
Public delegate TOutput Converter <TOutput, TIntput> (TIntput from );
 
}
Public class SortedList <Tkey, Tvalue>
{
 
}
 
}
 
}
 
 
 
//////////////////////////////////////// //////////////////////////////////////// //////
 
// The following is another example. About the FindAll method and Find // of List <T> //
 
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Collections;
Using System. Collections. Specialized;
 
Namespace generic
{
Public class Racer
{
Private string name;
 
Public string Name
{
Get {return name ;}
}
Private string car;
 
Public string Car
{
Get {return car ;}
}
 
Public Racer (string name, string car)
{
This. name = name;
This. car = car;
 
}
Public override string ToString ()
{
Return string. Format ("Name: {0,-20} Car: {1}", Name, Car );
}
}
 
Public class MainRun
{
Static void Main ()
{
List <Racer> racers = new List <Racer> ();
Racers. Add (new Racer ("James", "Audi "));
Racers. Add (new Racer ("Li Si", "rotten car "));
 
// Foreach (Racer item in racers)
//{
// Console. WriteLine (item );
//}
FindRacer finder = new FindRacer ("Audi ");
 
Foreach (Racer item in racers. FindAll (new Predicate <Racer> (finder. DrivingCarPredicate) // This is the FindAll of the generic List.
{
Console. WriteLine (item );
}
 
}
 
}
 
Public class FindRacer
{
Private string car;
Public FindRacer (string car)
{
This. car = car;
 
}
 
Public bool DrivingCarPredicate (Racer racer)
{
Return racer. Car = car;
}
}
 
}