- Home /
Question by
useless.unity.user · May 24, 2012 at 03:16 AM ·
componentgeneric
Convert UnityEngine.Component to T
I need to convert a bound (UnityEngine.Component) List to a generic (T) List, is this possible? how?
thanks!
Comment
Answer by whydoidoit · May 27, 2012 at 11:40 AM
That's not really how generics work. The T in a generic is filled in when you call a function or instantiate a class.
public class myClass<T>
{
public List<T> someList = new List<T>();
}
Then later
var anObject = new myClass<string>();
anObject.someList.Add("Hello world");
var anotherOther = new myClass<int>();
anotherObject.someList.Add(100);
The List has been created from the generic parameters when I constructed the class.
Perhaps edit the question if your problem is actually something different....