Generic Interface : Generic Interface « Generic « C# / CSharp Tutorial






using System;
using System.Collections.Generic;

interface GenericInterface<T>              
{
   T getValue(T tValue);
}

class MyClass<T> : GenericInterface<T>     
{
   public T getValue(T tValue)    
   {
      return tValue;
   }
}

class MainClass
{
   static void Main()
   {
      MyClass<int>    intObject    = new MyClass<int>();
      MyClass<string> stringObject = new MyClass<string>();

      Console.WriteLine("{0}", intObject.getValue(5));
      Console.WriteLine("{0}", stringObject.getValue("Hi there."));
   }
}
5
Hi there.








18.17.Generic Interface
18.17.1.Generic Interface
18.17.2.Implement multiple generic interfaces by a non-generic class
18.17.3.Generic IEquatable
18.17.4.Declaring a Generic Interface, Implementing a Generic Interface
18.17.5.Declaring a Generic with Multiple Type Parameters
18.17.6.Generic Interface for binary operation