I have this:
var doc = new XmlDocument();
doc.LoadXml("<XMLHERE/>"); //This returns void
How do I combine into one statement?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t, lest you lose the reference to the document (
doc) and therefore find it to be inaccessible.As other answers have began filtering in to contradict my assertion, what I will say is this. Of course, you can create a method to do ‘the dirty work’ for you, but then you’re not really just turning this into a one-liner, you’re just disjointing the creation (and not really saving unless you need to write this in hundreds of different places).
This might not be a bad thing in many situations, but defining a class with a single extension method to facilitate this seems ridiculous. Specifying it locally, within a class where this would be extensively utilised could be a different matter.
All in all, my answer still stands fundamentally, not considering the many contrived ways you might ‘get around’ this.