XElement 内部是否存储实现 IEnumerable 的对象?作为字符串内容(因此作为 XText )?
在以下示例中,XElement
如何在内部存储实现 IEnumerable
的对象?是否对该集合中存储的每个 A 类型对象调用 ToString
,并且结果值被视为字符串内容(作为 XText
)以及因此附加到“someString”值,或者......?
class Program
{
static void Main(string[] args)
{
A[] = new A[10];
for (int i = 0; i < 10; i++)
a[i] = new A();
XElement element = new XElement("XMLElement", "someString", a);
Console.WriteLine(element);
}
}
class A { }
谢谢
How does in the following example XElement
internally store an object implementing IEnumerable<A>
? Is ToString
called on each of A type objects stored in this collection and the resulting value is treated as a string content ( as aXText
) and is thus appended to "someString" value, or ...?
class Program
{
static void Main(string[] args)
{
A[] = new A[10];
for (int i = 0; i < 10; i++)
a[i] = new A();
XElement element = new XElement("XMLElement", "someString", a);
Console.WriteLine(element);
}
}
class A { }
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 http://msdn.microsoft.com/en-us/library/bb943882。 aspx 了解您可以使用构造函数和方法(如 Add)作为
XDocuments
和XElements
的内容传入的内容。对于您的
A
实例,调用 ToString() 是正确的,并且附加调用的每个结果以形成“XMLElement”的单个XText
子节点的值“您创建的XElement
。See http://msdn.microsoft.com/en-us/library/bb943882.aspx for an explanation what you can pass in as contents of
XDocuments
andXElements
with the constructors and methods like Add.For your
A
instances you are right that ToString() is called and that each result of that called is appended to form the Value of a singleXText
child node of the "XMLElement"XElement
you create.