Search code examples
c#xelement

When using an XElement once, declare inline or create its own object?


When I am using an XElement once, should I declare it inline e.g.

user.name = new XElement("Name", "John Doe");

or declare the XElement on its own line, e.g.

XElement elem =  new XElement("Name", "John Doe");
user.name = elem;

Solution

  • Use whatever you like. The compiler will optimize it to the same thing anyway.