none
convert xdocument to integer RRS feed

  • Question

  • In a C# 2010 application, I have the following value obtained from an Xdocument,

    pacDet.Element("TotTran").Value.

    I would like to know how to change this xdocument type to an integer data type.

    Tuesday, September 11, 2012 10:11 PM

Answers

  • Try this:
     
        int tt = 0;
        string val = pacDet.Element("TotTran").Value;
        int.TryParse(val, out tt);

    --
    Mike
    • Marked as answer by wendy elizabeth Wednesday, September 12, 2012 1:38 AM
    Tuesday, September 11, 2012 10:26 PM

All replies

  • Try this:
     
        int tt = 0;
        string val = pacDet.Element("TotTran").Value;
        int.TryParse(val, out tt);

    --
    Mike
    • Marked as answer by wendy elizabeth Wednesday, September 12, 2012 1:38 AM
    Tuesday, September 11, 2012 10:26 PM
  • You can always use Convert.ToInt32(pacDet.Element("").Value);

    Mark it as helpful if so!!! thanks, Mithilesh

    Tuesday, September 11, 2012 10:52 PM
  • Hi wendy;

    To your question, "I would like to know how to change this xdocument type to an integer data type.", You can convert it to an integer by casting it to int, like this.

    (int) pacDet.Element("TotTran")

    The above line will return an value of integer data type.

       


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, September 11, 2012 11:45 PM