Sunday, September 8, 2013

Generics in C#

GENERICS IN C# 2.0

                           Generics features was introduced in the .net framework 2.0. Generic refer to the technique for writing a class without specifying data type that the class works with. This generic classes allowing to work with many different data type  without needing to be rewritten it


Generic Parameter
  Genereic parameter in the generic class can be identified by  "<" and " >" brackets in class. 

public class Stack<T>
{
   T[] m_Items; 
   public void Push(T item)
   {...}
   public T Pop()
   {...}
}
Stack<int> stack = new Stack<int>();
stack.Push(1);
stack.Push(2);