将IList 投射到T []类型的数组是否会导致枚举?(Does casting an IList to an array of type T[] cause enumeration?)

编程入门 行业动态 更新时间:2024-10-25 22:34:06
将IList 投射到T []类型的数组是否会导致枚举?(Does casting an IList to an array of type T[] cause enumeration?)

我有一个看起来像这样的方法:

T[] field; public Method(IList<T> argument) { this.field = (T[])argument; }

当方法的主体执行时,枚举是否在投射期间发生? 如果底层类型不同,会不会改变?

I have a method that looks like:

T[] field; public Method(IList<T> argument) { this.field = (T[])argument; }

When the body of the method is executed does enumeration take place during the cast? Would that change if the underlying type was different?

最满意答案

不,它不会列举任何东西。 如果argument实际上一个T[] ,它将成功,如果它不是,则抛出一个InvalidCastException异常。 (如果argument为null,则返回null。)

No, it won't enumerate anything. It will either succeed if argument actually is a T[], or throw an InvalidCastException exception if it isn't. (Or return null if argument is null.)

更多推荐

本文发布于:2023-08-07 16:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   是否会   类型   IList   enumeration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!