1

So, I have a interface:

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

and I have an class:

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

But this is causes syntax error's, what i want, is to force someVariable to be derivative of

A<AnyType>

so i can do that:

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

Can u pls tell me, how to fix that?

Here is the actual code:

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>
{
   .......
2
  • where ShouldBeClassA<AnyType>> : A<AnyType> has an extra >, that's your syntax error. Commented Feb 26, 2017 at 13:03
  • 1
    C# does not have templates. It has Generics. The generic type argument can be constrained, which is what where is. Ive suggested an edit to the title and tags to reflect this. Commented Feb 26, 2017 at 14:20

1 Answer 1

1

Your interface should be:

public interface IGenericTeacher<T> where T : IGenome<T>
{
    //...
}
Sign up to request clarification or add additional context in comments.

1 Comment

That mistake ive made was cuz i was hurry, so, ive added the actual code, that's not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.