How can I store an xml node value into a string variable RRS feed

  • Question

  • I am trying to store he following value of xml into a string variable. It is not working. But if I am using List<string> it would be working. But I don't need to use list string variable  for mailsubject. The mailsubject is only one tag. there is no mutiple tag. So I would like to use string variable to store mailsubject rather than List<string> Please help

    string _mailsubject =
                            .Select(c => c.InnerText.Trim())
                            .ToString(); //  it is not working the value is not coming from xml
    <MailBody>Please find statement</MailBody>


    Friday, July 5, 2019 11:05 AM


  • SelectNodes() will always give you a List of items even if only one matching item was found. In that case you will get a List with one entry.

    Replace .ToString() with .FirstOrDefault() and you're done.



    will do the same. But be sure you have at least one item (index 0) found.

    Friday, July 5, 2019 11:13 AM