C#带约束的继承泛型类

C#带约束的继承泛型类,c#,generics,inheritance,generic-constraints,C#,Generics,Inheritance,Generic Constraints,因此,我有一个界面: interface A<SomeType> { SomeType Abc(SomeType); ..... } 你能告诉我怎么解决吗 以下是实际代码: public interface IGenericTeacher<Genome<GenomeType>> where Genome<GenomeType> : IGenome<GenomeType> { /// <summa

因此,我有一个界面:

interface A<SomeType>
{
    SomeType Abc(SomeType);
    .....
}
你能告诉我怎么解决吗

以下是实际代码:

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>
{
   .......
公共接口IGenericTeacher
何处基因组:IGenome
{
/// 
///通过测试并保存结果。
/// 
无效通过测试();
/// 
///根据结果,传递一代。
/// 
void PassGeneration();
}
公共接口IGenome
{
.......

您的界面应该是:

public interface IGenericTeacher<T> where T : IGenome<T>
{
    //...
}
公共接口IGenericTeacher其中T:IGenome
{
//...
}

where ShouldBeClassA>:A
有一个额外的
,这是你的语法错误。C#没有模板。它有泛型。泛型类型参数可以被约束,这就是
where
的所在。我建议编辑标题和标记以反映这一点。我犯的错误是因为我很匆忙,所以,我添加了实际代码,这不起作用
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>
{
   .......
public interface IGenericTeacher<T> where T : IGenome<T>
{
    //...
}