這個問題在這里已經有了答案: 按索引獲取串列項 6 個答案 6 小時前關閉。
我想在指定索引處從我的 List<Func> 中獲取一個元素?
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();
}
}
uj5u.com熱心網友回復:
該陳述句_element()無效的原因是因為_element是一個串列而不是一個Func,因此缺少一個()或.Invoke()。您需要使用索引器List<>來檢索Func您嘗試呼叫的。
public void Method(int index)
{
Type type = _element[index]();
/* do stuff with 'type' */
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422149.html
標籤:
