I Want to get an Element from my List<Func> at a specified index ?
public classe Exemple
{
private readonly List<Func<Type>> _element ;
public Exemple(List<Func<Type>> element)
{
_element = element;
}
public void Method(int index)
{
Type type= _element();
}
}
>Solution :
The reason the statement _element() is invalid is because _element is a list and not a Func, therefore lacking a () or .Invoke(). You need to use the indexer of List<> to retrieve the Func that you are trying to invoke.
public void Method(int index)
{
Type type = _element[index]();
/* do stuff with 'type' */
}