Boolean to String

S

shapper

Hello,

I am querying a XDocument as follows:

Boolean test = true;

IEnumerable<XElement> test1 = _albums.Root.Elements("Album").Where(a
=> a.Element("Active").Value == test.ToString());

IEnumerable<XElement> test2 = _albums.Root.Elements("Album").Where(a
=> a.Element("Active").Value == "true");

The first one where I use test.ToString() I get an empty enumeration.

On the second one where I use "true" I get 4 items.

What am I missing?

Thanks,
Miguel
 
A

Arne Vajhøj

I am querying a XDocument as follows:

Boolean test = true;

IEnumerable<XElement> test1 = _albums.Root.Elements("Album").Where(a
=> a.Element("Active").Value == test.ToString());

IEnumerable<XElement> test2 = _albums.Root.Elements("Album").Where(a
=> a.Element("Active").Value == "true");

The first one where I use test.ToString() I get an empty enumeration.

On the second one where I use "true" I get 4 items.

What am I missing?

Maybe that test.ToString() returns "True" not "true".

Arne
 
S

shapper

Maybe that test.ToString() returns "True" not "true".

Arne

Yes that is correct. I solved it ...

The problem was that when saving to the XML file it was saved as
"true".
But when I compare the ToString() generates "True".

Thanks,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Linq Query 5
XML ID ... 7
Linq > Get XML Node 2
XMLElement and Type Parse. 1
Unit of work and Service dealing with XDocument 10
Byte Array 4
XML to Dictionary using LINQ 2
LINQ and XML for compact framework 24

Top