Can someone explain to me why this is not true in C #:
namespace NamespaceA { public class ClassA<T1> { T1 mT1; public T1 Type1 { get { return mT1; } } } public class IOForClassA { public interface ICanOutput { void OutputFunction(); } public static void Output(ClassA<ICanOutput> aClassA_WithOutputCapabilities) { aClassA_WithOutputCapabilities.Type1.OutputFunction(); } } } namespace NamespaceB { public class ClassB { public class OutputableClassA : NamespaceA.IOForClassA.ICanOutput { public void OutputFunction() { } } public ClassB() { NamespaceA.ClassA<OutputableClassA> aOutputableA = new NamespaceA.ClassA<OutputableClassA>(); NamespaceA.IOForClassA.Output(aOutputableA); } } }
This will result in a compilation error:
Argument 1: cannot be converted from "NamespaceA.ClassA" <"NamespaceB.ClassB.OutputableClassA"> "to the namespace A..ClassA" <"NamespaceA.IOForClassA.ICanOutput"> "
... but NamespaceB.ClassB.OutputableClassA implements NameSpaceA.IoForClassA.ICanOutput, so I donβt understand why this is the problem ...
I am trying to allow the user to create ClassA of any type that he wishes. However, if they want ClassA to be "deducible," its template type must implement a specific interface.
source share