我有以下聲明:Lambda表達式用的valueOf一個通用的IEnumerable
AnotherClass temp = myCustomList
.Where(x => x.bTyp != null && x.bTyp is IEnumerable<T>)
.FirstOrDefault();`
上述聲明說,temp
是null
,但它shouln't是。
T
得到一個通用值List
的MyCustomClass
就像List<MyCustomClass>
。作爲值typeof(IEnumerable<MyCustomClass>))
。
調試器讓我對myCustomList
是這樣的:
bTyp = {System.Collections.Generic.IEnumerable
1 ... MyCustomClass]}`
我應該如何改寫聲明temp
不null
,並會返回一個結果?
你可以檢查對象本身是否爲空而不是類型? – Jacobr365
是的,但它有8個元素('List'),所以它不是'null'。 –
kkkk00999
http://stackoverflow.com/questions/2404993/is-it-possible-to-define-a-generic -lambda – willaien