'This' Reference for Generic Types : Generic Class « Generics « C# / C Sharp






'This' Reference for Generic Types

 

    using System;

    public class Starter{
        public static void Main(){
            MyGenericClass<int> obj=new MyGenericClass<int>();
            obj.MethodA();
        }
    }
    
    class MyGenericClass<T> {
        public T MethodA() {
           T var=default(T);
           Console.WriteLine(this.GetType().ToString());
           return var;
        }
    }

           
         
  








Related examples in the same category

1.A simple generic classA simple generic class
2.Declare the generic class.
3.A Generic Class with Two Type ParametersA Generic Class with Two Type Parameters
4.Generic Fields
5.Create relationship between two type parameters
6.Demonstrate the default keywordDemonstrate the default keyword
7.Comparing Instances of a Type ParameterComparing Instances of a Type Parameter
8.Generic class with interfaceGeneric class with interface