1

所以,我有一个界面:

interface A<SomeType>
{
    SomeType Abc(SomeType);
    .....
}

我有一堂课:

class B<ShouldBeClassA<AnyType>> 
     where ShouldBeClassA<AnyType> : A<AnyType>
{ ShouldBeClassA<AnyType> someVariable; .....}

但这会导致语法错误,我想要的是强制 someVariable 衍生

A<AnyType>

所以我可以这样做:

class B......
{
    ....
    void Method()
    {
        someVariable.Abc(anyTypeVariable);
    }
 ......}

你能告诉我,如何解决这个问题吗?

这是实际的代码:

public interface IGenericTeacher<Genome<GenomeType>>
    where Genome<GenomeType> : IGenome<GenomeType>
{

    /// <summary>
    /// Pass the tests and save the results.
    /// </summary>
    void PassTests();

    /// <summary>
    /// Passing generation, according to the results.
    /// </summary>
    void PassGeneration();

}


public interface IGenome<GenomeType>
{
   .......
4

1 回答 1

1

你的界面应该是:

public interface IGenericTeacher<T> where T : IGenome<T>
{
    //...
}
于 2017-02-26T14:01:14.257 回答