Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I retrieve first item from a Collection?

I dont know how to retrieve first Item from this collection :

IGrouping<string, Plantilla> groupCast = group as System.Linq.IGrouping<string, Plantilla>;

I also tryed :

IGrouping<string, Plantilla> firstFromGroup = groupCast.FirstOrDefault();

but not works cause and explicit conversion already exist

like image 745
Jonathan Escobedo Avatar asked Feb 25 '09 19:02

Jonathan Escobedo


1 Answers

Why not just use var?

var firstFromGroup = group.First();

As for the reason you're getting an error, I'm guessing either the Key or Element is different than what you think they are. Take a look at the rest of the error message to see what types the compiler is complaining about. Note that if there is an anonymous type involved, the only way to get it is using var.

like image 148
lc. Avatar answered Oct 31 '22 16:10

lc.