Sanjeev Singh
How to Create Generics in .NET 2.0
By Sanjeev Singh in ASP.NET on Dec 01 2008
  • Bechir Bejaoui
    Dec, 2008 1


    I give you an example

    imagine that you have a rectangle, its dimentions could be either int, double, long and so forth

    public class Rectangle <T>
    {
          public Rectangle()
          {
              
          }
          public T width{get;set;}
          public T height{get;set;}
          .
          .
          .
    }

    So when the user defines his/her rectangle instance he/she also define the type of the width and the height

    Rectangle<int> oRectangle = new Rectangle();
    Rectangle<long> oRectangle = new Rectangle();
    Rectangle<double> oRectangle = new Rectangle();

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS