简体   繁体   中英

How to Add Generic Constraint to C# class which inherits from other class?

I am attempting to create a class with a generic constraint which inherits from another class-- I am running into a compilation error:

  public  class  BaseEntityController<T> where T : BaseEntity  : BaseController
    {

    }

This code won't compile - I get "unexpected token error". Is there a way to do this?

Try this:

public class BaseEntityController<T> : BaseController where T : BaseEntity
{
}

How about

public  class  BaseEntityController<T> : BaseController where T : BaseEntity
{

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM