Reputation: 1421
I've got this classes:
public class MyClassContainer<T> where T:MyClass
{
private List<T> _classList = new List<T>();
public MyClassContainer(params MyClass[] myClasses)
{
for (int i = 0 ; i < myClasses.Length; ++i)
{
myClasses[i].container = this; // ERROR: Cannot implicitly cast...
_classList.Add(myClasses[i]);
}
}
...
}
public abstract MyClass: IMyclass
{
public MyClassContainer<MyClass> container
{
get;
set;
}
...
}
That code has an error in this line myClasses[i].container = this;
. It said:
Cannot implicitly convert type MyClassContainer<T> to MyClassContainer<MyClass>
What did I do wrong here? Thanks.
PS: I'm not used to using generics so it's probably because of that although I don't know why it went wrong.
Upvotes: 1
Views: 130
Reputation: 346
Try using as
instead of cast
myClasses[i].container = this as MyClassContainer<MyClass>;
Upvotes: 1