0

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;
j_mcnally
  • 6,928
  • 2
  • 31
  • 46
Meyer Denney
  • 796
  • 1
  • 11
  • 34

3 Answers3

1

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

David Yaw
  • 27,383
  • 4
  • 60
  • 93
0

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

is fine if you are only going to use it once. saves a few bytes for the extra pointer.

j_mcnally
  • 6,928
  • 2
  • 31
  • 46
0

I think the fact that you don't have a meaningful name ("elem") for the XElement variable is telling. The XElement only has meaning assigned to name, so I'd do it inline.

Foo42
  • 3,024
  • 4
  • 22
  • 17