C# implement interface on "where TEntity : class"

I'm relatively new to .NET and I've stumbled on this particular issue: while following a tutorial on repository pattern, the definition of the class goes like this:

public class GenericRepository<TEntity> where TEntity : class { ...

That being said, this class is supposed to implement an interface. Since I already used the : operator, how do I do that?

I tried going public class GenericRepository<TEntity> : IGenericRepository where TEntity : class { and also public class GenericRepository<TEntity> where TEntity : class : IGenericRepository { but it doesnt work

Jon Skeet
people
quotationmark

Since I already used the : operator, how do I do that?

: isn't an operator - you're just using it in the generic type constraint. You can still specify an interface to implement.

This should be fine:

public class GenericRepository<TEntity> : IGenericRepository where TEntity : class

Or if IGenericRepository is a generic interface, you might want:

public class GenericRepository<TEntity> : IGenericRepository<TEntity>
    where TEntity : class

people

See more on this question at Stackoverflow