C
CSharper
I have following XML
<root>
<Person id="1">
<Name>a</Name>
</Person>
<Person id="2">
<Name>b</Name>
</Person>
</root>
I am trying to find the person with id = 1 and I use the following
var people =
doc.Decendents().Elements("Person").Where(s=>s.Attribute("id").Value.Equals("1"));
When I run I get an empty list but when I change this to pure linq
var people = from c in doc.Decendents().Elements("Person")
where c.Attributes().Count() > 0
&& c.Attribute("id") != null
&& c.Attribute("id").Value.Equals("1")
select c;
This one does return me the first note.
I have two questions here;
Is it possible to include all these && conditions in the Lambda
(stupid question) since most of all the examples I have seen are one
liners. Also what is the difference between the lambda and linq in
this selection that doesn't return the value? One side note, which is
the good way to code, lambda or linq? I see the benefits of linq but
for an untrained eye lambda could be confusing.
Thanks.
<root>
<Person id="1">
<Name>a</Name>
</Person>
<Person id="2">
<Name>b</Name>
</Person>
</root>
I am trying to find the person with id = 1 and I use the following
var people =
doc.Decendents().Elements("Person").Where(s=>s.Attribute("id").Value.Equals("1"));
When I run I get an empty list but when I change this to pure linq
var people = from c in doc.Decendents().Elements("Person")
where c.Attributes().Count() > 0
&& c.Attribute("id") != null
&& c.Attribute("id").Value.Equals("1")
select c;
This one does return me the first note.
I have two questions here;
Is it possible to include all these && conditions in the Lambda
(stupid question) since most of all the examples I have seen are one
liners. Also what is the difference between the lambda and linq in
this selection that doesn't return the value? One side note, which is
the good way to code, lambda or linq? I see the benefits of linq but
for an untrained eye lambda could be confusing.
Thanks.