如何获得IEnumerable的第一个元素 [英] How to get the first element of IEnumerable

查看:202
本文介绍了如何获得IEnumerable的第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有更好的方法来获取IEnumerable类型的第一个元素:

Is there a better way getting the first element of IEnumerable type of this:

foreach (Image image in imgList)
{
     picture.Width = (short)image.Columns;
     picture.Height = (short)image.Rows;
     break;
}

这是该类型的确切声明:

This is the exact declaration of the type:

public class ImageList : IEnumerable, IDisposable

推荐答案

var firstImage = imgList.Cast<Image>().First();

这篇关于如何获得IEnumerable的第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆