I was busy creating a generic method to convert a
List to a
DataTable when I received the error:
Constraint cannot be special class 'object'
on this statement:
public DataTable ListToDataTable(IList list) where T : Object
Blegh... why would this be? Anyhow, I did a workaround by changing the statement to the following:
public DataTable ListToDataTable(T list) where T : IList
A bit annoying, since now one has to send a
List
3 comments:
I think what you want is "where T : class" (although this would also compile without any constraint at all)
Another way to solve this, is to use the new() constraint.
Example:
public DataTable ListToDataTable(T list) where T : new()
This way T must be a object with a parameterless constructor!
Does where T : class get us anywhere?
Post a Comment