我有以下功能:C#:將一個通用的功能函數求對象
private int GetEnumTypeUnderlyingId<T>()
{
return (int)Enum.Parse(typeof(T), Enum.GetName(typeof(T), _franchise.LogonDialog));
}
我想將其轉換爲Func type
。我寫了這樣的:
Func<int> GetEnumTypeUnderlyingIdFunc<T> =() => (int)Enum.Parse(typeof(T), Enum.GetName(typeof(T), _franchise.LogonDialog));
但這不起作用。在使用Func <>,泛型和lambda表達式時,我不是很舒服,因此任何幫助都將不勝感激
它不會這樣工作,因爲C#不支持通用屬性 –