I have this code:
MyObject Obj {get;set;}
var x = from xml in xmlDocument.Descendants("Master")
select new MyObject
{
PropOne = //code to get data from xml
PropTwo = //code to get data from xml
}
The result is var
being IEnumerable<MyObject>
, and I need to use a foreach
loop to assign x
to Obj
:
foreach(var i in x)
{
Obj = i;
}
Is there a way I can use a LINQ statement and not have an IEnumerable
returned in that way? Or is it normal to use a foreach
loop the way I am?