The type 'T' must be a reference type in order to use it as parameter 'TEntity' in the generic type or method 'System.Data.Linq.Table<TEntity>'
ErrorMessage:The type 'T' must be a reference type in order to use it as parameter 'TEntity' in the generic type or method 'System.Data.Linq.Table<TEntity>'
Solution1:
错误:private void GetOrDefaultUDC<T>(Table<T> table, string what, int whatID, int mapID, out int id, out Object value)
where T: IUDC, new()
错误:private void GetOrDefaultUDC<T>(Table<T> table, string what, int whatID, int mapID, out int id, out Object value)
where T: class, IUDC, new()
说明:关键词是reference,见到它就补一个class(尽管从IUDC派生多半已经是class了)。这里出现此约束的原因是在Table的声明中,声明了凡是Table<T>中的T必须是个class,具体声明是:public sealed class Table<TEntity> : IQueryProvider, ITable, IListSource, ITable<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>, IQueryable, IEnumerable where TEntity : class
ErrorMessage:c# generics error: The constraints for type parameter '
Solution2:
|
getting the following error:
class:
interface:
|
|
|
You are restricting your T generic parameter to class in your implementation. You don't have this constraint on your interface. You need to remove it from your class or add it to your interface to let the code compile: Since you are calling the method
|
|||||||||||||
|
|
You either need to apply the constraint to the interface method as well or remove it from the implementation. You are changing the interface contract by changing the constraint on the implementation - this isn't allowed.
|
|
|
You need to constrain your interface, too.
|
出处:http://www.cnblogs.com/dairongle/archive/2011/04/02/2401275.html
参考:http://stackoverflow.com/questions/11845964/c-sharp-generics-error-the-constraints-for-type-parameter-t-of-method

浙公网安备 33010602011771号