String Conversion

S

shapper

Hello,

I am getting a few values from a XML file using LINQ.
I need to convert two values to Boolean and to DateTime.
The DateTime string in the XML file was created simply using
DateTime.UtcNow.ToString().

I have:
IQueryable<Bag> bags = (from b in XElement.Load("../Data/
Bags.xml").Elements("Bags");
orderby b.Element
("Updated").Value descending
select new Bag {
Id = new Guid
(b.Element("Id").Value),
Content = b.Element
("Content").Value,
Created = b.Element
("Created").Value,
Name = b.Element
("Name").Value,
Open = b.Element
("Open").Value
}).AsQueryable();

I need to convert the values Created (DateTime) and Open (Boolean)

What is the best way to do this?

Thanks,
Miguel
 
S

shapper

[...]
I need to convert the values Created (DateTime) and Open (Boolean)
What is the best way to do this?

Is there something about the bool.Parse() and DateTime.Parse() methods  
that don't work for you?

Note that in your question, there appears to be no relevance at all to the  
fact that you're reading XML or using LINQ.  Those pieces of information  
only distract from what your actual question is (a distraction compounded 
by the fact that your code doesn't even compile).

Pete

Hi Pete,

In the meanwhile I had solved it using Boolean.Parse and
DateTime.Parse ...

I asked using my XML code because there might be a specific way to do
this when reading XML files. I wasn't sure about it so I wanted to
give a complete explanation on how I was using it.
 

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

Top