代码之家  ›  专栏  ›  技术社区  ›  Matt W

如何使用linq,c向元素添加属性?

  •  2
  • Matt W  · 技术社区  · 15 年前

    我有一个xelement对象,它有许多属性,我只想向元素添加另一个属性。

    我该怎么做?

    2 回复  |  直到 9 年前
        1
  •  8
  •   Robin Day    15 年前
    xElement.Add(new XAttribute("Foo", "Bar"));
    
        2
  •  2
  •   Alexander    9 年前

    要使用属性创建元素,请执行以下操作:
    var xmlTest = new XElement("XmlElementName", new XAttribute("XmlAttributeName", "AttributeValue"));