Question by
Juggernaut6983 · Jun 16, 2018 at 01:46 AM ·
genericsdelegatestypes
Trying to loop through a generic list -- need help.
I have a function that receives a delegate function as a parameter. The delegate function returns a List . I am trying to take that list and loop through and get names from the list; I get an error at list[i].name.
"T does not contain a definition for 'name'......(are you missing a using dir or assbly ref?)." I think I need to get the type from the delegate function that was pass as a param, not sure how though. Thanks for the help!
public delegate List<T> ListForWindow<T>();
public void ShowImageSelectWindow<T>( ListForWindow<T> getList)
{
List<T> list = getList.Invoke() as List<T>;
for(int i = 0; i < list.Count ; i++)
{
GameObject obj = Instantiate(imageListElement, listParent);
obj.GetComponent<ImageListElement>().SetupElement( list[i].name );
}
}
Comment