I recently wrote a code snippet that looked something like this:
IEnumerable<DTO.Employee> xEmployee =
from e in xDoc.Descendants("Employee")
where int.Parse(e.Attribute("Id").Value) == emp.Id
select new DTO.Employee
{
Id = (int)e.Attribute("Id"),
LastName = (string)e.Element("LastName"),
FirstName = (string)e.Element("FirstName"),
Email = (string)e.Element("Email")
};
However, I am confused about casting to int in the where clause. First, I wrote something like
where (int)(e.Attribute("Id").Value) == emp.Id
which did not compile. Why can I explicitly press (e.Attribute ("Id")) but cannot do it (e.Attribute ("Id"). Value)?
Peter source
share