我希望能够使用C#Linq到Xml输出以下格式。简单的C#Linq到Xml
<Genres>
<Genre Value="Rock" />
<Genre Value="Metal" />
</Genres>
考虑以下功能。我想评估每个参数,但只添加那些不是空字符串的参数。
private XmlElement createGenresXml(string str1 = "", string str2 = "Rock", string str3 = "Metal", string str4 = "")
{
'Return XmlElement should look like the Xml above.
}
谢谢! \ M/\ M/
#1不提供代码编写的服务。如果您有任何问题,请随时留言。不用客气。 – vendettamit
我不认为LINQ是真的适合这个任务,因为你有一堆独立的参数。为什么不使用一些'if'来将元素放在一起? – litelite
如果你想使用Linq,那么使用'XElement'而不是'XmlElement'。 – juharr