2
public void display()
{
    var Charts = chartGroup.Descendants("charts").Elements("chart")
        .Where(x => x.Attribute("id").Value == "4")
        .Select(x => x.Attribute("name").Value).ToList();
}

I had written following lambda expression. As of now this works fine. But I want to set search value as user parameter ..something like

public void display(int userid)
{
    var Charts = chartGroup.Descendants("charts").Elements("chart")
        .Where(x => x.Attribute("id").Value == userid)
        .Select(x => x.Attribute("name").Value).ToList();
}

But it gives error. Please help out how to solve this?

1
  • How many guesses of the error do I get? Commented Nov 25, 2013 at 4:47

2 Answers 2

1

Comparing an int and a string makes no sense:

public void display(int userid) {
 var Charts = chartGroup.Descendants("charts")
                        .Elements("chart")
                        .Where(x =>  x.Attribute("id").Value == userid.ToString())
                        .Select(x => x.Attribute("name").Value).ToList();
}
Sign up to request clarification or add additional context in comments.

Comments

0

Search pattern has to be string but you are passing as int. So convert it ToString() .

 var Charts = 
            chartGroup.Descendants("charts").Elements("chart").
            Where(x => x.Attribute("id").Value == userid.ToString()).
            Select(x => x.Attribute("name").Value).ToList();

Comments

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.