-1
在最小的奇怪,但我相信存在一個解釋... 我有一個接口(IRepository)與6個方法要實現的類。但是當我放置代碼來實現接口時,VS2015不顯示給我實現類的選項,如果我沒有手動實現並編譯項目,它不會顯示編譯錯誤,不應該嗎?如果它顯示編譯錯誤告訴我,我沒有實現接口。沒有編譯錯誤的一個未實現的接口
接口:
public interface IRepository<T> where T : class
{
IQueryable<T> GetAll();
IQueryable<T> FindBy (Expression<Func<T, bool>> predicate);
void Add (T entity);
void Delete (T entity);
void Edit (T entity);
void Save();
}
類應該實現IRepository,而不是工具,它不會拋出一個編譯錯誤:
public class GenericRepository<T> where T : class, IRepository<T>
{
}
經過一番在谷歌搜索我發現的問題:它應該這樣寫:** public class GenericRepository:IRepository 其中TEntity:class' ** –
c2s
就像下面寫的答案? 'TEntity'或'T',沒關係。 – user3185569