I have various classes that implements IActiveRecord.
I want to have a method where I pass in a newly created class and assign ActiveRecord to the type of the class passed in.
I have tried the below but it does not compile for some reason.
Any ideas?
private void AddRecord<T>() where T : class, new()
{
IActiveRecord ActiveRecord = (IActiveRecord)T;
}
Your question is unclear, but if I understand correctly what you are trying to do, you just need to add the constraint
where T : IActiveRecord. Then you can sayRegarding your line
this is not legal.
Tis a type parameter, not an expression that you can cast.