none
abstract class doubt ??

    Question

  • what's the difference between the first abstract class and second abstract class .. when and where to use the first type and second type .. Please give me some info on it ...

    First Abstract Class

            public abstract class Test<T> where T : class
            {

            }


    Second Abstract Class

            public abstract class Test
            {

            }


    Regards, Gullu.
    Friday, June 04, 2010 6:39 AM

Answers

  • The second class is just a general abstract class - class that cannot be instantiated and is meant to provide common definition of a base class that multiple derived classes can share. More about abstract classes on MSDN.

    The first one is a generic abstract class that uses constraints to place requirements on the generic parameter (T). In your case the generic parameter can only be a type that match or inherit from specific base (you call this type 'class').

    e.g.

     

     

    public class Testable
    {
    
     public void Test()
     {
      //some logic here
     }
    
    }
    
    
    public abstract class Test<T> where T : Testable
    {
      public T t1;
    
      public void DoWork()
      {
       t1.Test(); //this will work because T must be of type Testable
      }
    }

     

    More about constraints on MSDN.

    Friday, June 04, 2010 9:30 PM