简体   繁体   中英

C# with Linq XML

I'm a newbie, could someone please help me what type is the "Parts", I am unable to find the correct type and hence can't return the object "Parts". Thanks

private ???? load_parts()
{
     var element = XElement.Load("xml/suras.xml");
     **var** Parts= from var in element.Descendants("part")
                 orderby var.Attribute("index").Value
                 select new  dictSuras
                 {
                     PartIndex = Convert.ToInt32(var.Attribute("index").Value),
                     PartPosition = Convert.ToInt32(var.Attribute("position").Value),
                     PartName = var.Attribute("name").Value
                 };

     return  Parts;
 }

由于您正在选择new dictSuras ,因此返回值为IEnumerable<dictSuras>

Rather than an answer that gives the information the OP is looking for, I will give an answer that shows how to find it. It is easier for all of us I think.

In Visual Studio, if you mouse-over a variable, a tooltip is displayed that includes the variable's type. This is quite useful if you are like me and dislike var , as it lets you see at a glance what the actual type is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM