Declare the generic class. : Generic Class « Generics « C# / C Sharp






Declare the generic class.

 

public class GenericList<T>
{
    void Add(T input) { }
}
class TestGenericList
{
    private class ExampleClass { }
    static void Main()
    {
        // Declare a list of type int.
        GenericList<int> list1 = new GenericList<int>();

        // Declare a list of type string.
        GenericList<string> list2 = new GenericList<string>();

        // Declare a list of type ExampleClass.
        GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();
    }
}

   
  








Related examples in the same category

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