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();
If you can't use LINQ you could also get the enumerator directly by imgList.GetEnumerator()
And then do a .MoveNext()
to move to the first element.
.Current
will then give you the first element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With