This is my code :
protected IEnumerable<Hotel> Hotels;
protected Hotel Hotel;
Hotels = from Hotel hotel in new Hotels()
select hotel;
Response.Write("RES " + Hotels.Count() + "<br />");
if (Hotels.Count() > 0)
{
Hotel = Hotels.First();
}
Response.Write("RES " + Hotels.Count() + "<br />");
Response.Write("RES " + Hotels.Count() + "<br />");
Well, Hotels have 1 item on it. But the result it :
RES 1
RES 0
RES 1
Why? Seems that .First() make confusion with iterator? How can I fix it using IEnumberable? (without using another kind of list, I need IEnumerable).
prints
As expected, how are you filling the enumerable and what type are you creating it as?
If you are filling this via an un-executed queriable you might get weird behavior like this as it will pick the first useage (ie
First()in this case).