问题描述
对不起,我在其他论坛而不是c#上发布了我的问题.
Sorry i posted my issues in another forum instead of c#.
您能帮忙这个打击吗?
https://social.msdn.microsoft.com/Forums/zh-CN/270481ae-3734-4e39-8f61-1e11e91e4f82/read-xml?forum=linqtosql
https://social.msdn.microsoft.com/Forums/en-US/270481ae-3734-4e39-8f61-1e11e91e4f82/read-xml?forum=linqtosql
喜欢dotnet
推荐答案
List<XElement> lstuser = xelement.Elements().ToList();
int count = lstuser.Count; // = 2
如果要使用列表<用户>您可以使用LINQ Select方法为每个返回的XElement创建一个新的User对象:
If you want a List<User> you could use the LINQ Select method to create a new User object for each returned XElement:
List<User> lstuser = xelement.Elements().Select(element => new User()
{
Name = element.Element("Name").Value,
BirthTime = element.Element("BirthTime").Value,
}).ToList();
或者如果您需要UserList:
Or if you want a UserList:
UsersList userList = new UsersList()
{
User = xelement.Elements().Select(element => new User()
{
Name = element.Element("Name").Value,
BirthTime = element.Element("BirthTime").Value,
}).ToList()
};
希望有帮助.
请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
这篇关于阅读xml问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!