简体   繁体   English

C#OfType()-澄清

[英]C# OfType() -clarification

Do we use OfType() for filtering purpose ? 我们是否使用OfType()进行过滤?

Say example, 举例来说,

if i use 如果我用

object[] numbers = { null, 1.0, "two", 3, 4.30, 5, "six", 7.0 };
var doubles = numbers.OfType<double>();

It just filters double values. 它只是过滤双精度值。

Yes, it's both a filter (on the elements) and a "cast" (on the collection, not the elements). 是的,它既是过滤器(在元素上)又是“ cast”(在集合上,而不是元素上)。 In other words, it filters the elements down to only those of the specified type, and returns an enumerable of the specified type. 换句话说,它将仅过滤指定类型的元素,并返回指定类型的可枚举。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM