I've got a List of entities called usages
, from which I create an IEnumerable of entities of type AdminUsage
, as follows:
var models = usages.Select(u => new AdminUsage(u));
when I call .ToList()
on models
I get an IndexOutOfRange exception with the message "Index was outside the bounds of the array."
Why could this be happening, and how can I successfully get a List of type AdminUsage
from my original list usages
?
Edit: Ok, so actually the index that was out of range was inside the AdminUsage
constructor:
public AdminUsageModel(Usage usageDetails)
{
Title = usageDetails.UsageName[0]
}
So my revised question is why is the exception only thrown on the call .ToList()
and not on the original .Select()
?