Why is List not IEnumerable?

后端 未结 6 861
北海茫月
北海茫月 2021-01-05 02:01

[Edit: My apologies ... the original question wording was ambiguous and I was not getting the responses I am looking for]

For any class X that inherits from class Y,

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-05 02:40

    The question does not make sense iArr has value type in it because it is an array of ints. The only time you are going to not know what the type an element is at compile time is if you have a collection of object. Under that circumstance every element could be a different type cast as an object so you would have to check every element.

    e.g.

    IEnumerable arse = SomeMethodThatReturnsIEnumerable();    
    bool areAllValueTypes = arse.().All(x => x is ValueType);
    

提交回复
热议问题