Implement multiple generic interfaces by a non-generic class : Generic Interface « Generic « C# / CSharp Tutorial






using System;
using System.Collections.Generic;

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

class MyClass : GenericInterface<int>, GenericInterface<string>    
{
   public int getValue(int inValue)            
   {
      return inValue;
   }

   public string getValue(string inValue)      
   {
      return inValue;
   }
}

class MainClass
{
   static void Main()
   {
      MyClass TrivInt = new MyClass();
      MyClass TrivString = new MyClass();

      Console.WriteLine("{0}", TrivInt.getValue(5));
      Console.WriteLine("{0}", TrivString.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