I tried to insert an object into a generic BindingList.
But if I try to add a specific object the compiler says:
“Argument type … is not assignable to parameter type”
private void JoinLeaveItem<T>(BindingList<T> collection)
{
if (collection.GetType().GetGenericArguments()[0] == typeof(UserInformation))
{
var tmp = new UserInformation();
collection.Add(tmp);
}
}
Please help me
You cannot have objects of two different types that does not have a common anscestor in a strongly typed list. That is: In your case you will need to different collections unless your two (or more) classes have a common base class.
Try creating overloads instead, like this
Use it like this
Note: I’ve inlined the
tmpvariable.