0

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;
 }
1
  • You might also consider using the XAttribute explicit casting operators. For example, in doing so the line for PartIndex becomes: PartIndex = (int)var.Attribute("index"), which is not only less code, but the code that is gone was noisy ceremonial type code, what's left is IMO meaty. Commented Mar 31, 2012 at 3:22

2 Answers 2

5

Since you're selecting a new dictSuras, the return value is an IEnumerable<dictSuras>.

Sign up to request clarification or add additional context in comments.

1 Comment

@saafh, a word of advice: I highly recommend you check out ReSharper. It's great for things like this. With a single keystroke, you can convert your var declaration to the "real" type (in this case, IEnumerable<dictSuras>. I find it a huge boon, and it's exceedingly popular.
3

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.

2 Comments

+1, but it's useful if people aren't like you and do like var as well!
Indeed a very useful tip! I've been programming c#+wp7 programming only since yesterday :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.