Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6037167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:02:02+00:00 2026-05-23T06:02:02+00:00

Here is what I want to do: string parseCode = from x in xml.Descendants(LogType)

  • 0

Here is what I want to do:

string parseCode = from x in xml.Descendants("LogType")
                   where x.Attribute("ID").Value == string)ddlHistoryLogDefinitions.SelectedValue
                   select x.Attribute("ParseCode").Value;

But that gives error: “Cannot implicitly convert type ‘System.Collections.Generic.IEnumerable’ to ‘string'”

There will only be one value for x.Attribute("ParseCode") but it insists on returning type IEnumerable<string>. How can I extract that value into a string ?

EDIT: Thank you for your responses. Here is what worked for me:

string parseCode = (from x in xml.Descendants("LogType")
                    where x.Attribute("ID").Value == (string) ddlHistoryLogDefinitions.SelectedValue
                    select (string) x.Attribute("ParseCode").Value).FirstOrDefault();

This trick was wrapping the entire linq query in () before the .FirstOrDefault().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:02:03+00:00Added an answer on May 23, 2026 at 6:02 am

    Use .Single to select the only result if you know there will be one and only one:

    string parseCode = (from x in xml.Descendants("LogType")
                       where x.Attribute("ID").Value == string)ddlHistoryLogDefinitions.SelectedValue
                       select x.Attribute("ParseCode").Value).Single();
    

    Use .SingleOrDefault or .First If there might be none or more then one respectively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written method which should return string with data from select query, but
I want to create a spring bean as below. <bean id=qNameString class=javax.xml.xpath.XPathConstants.STRING/> Here I
I have XML stored in string variable: <ItemMasterList><ItemMaster><fpartno>xxx</fpartno><frev>000</frev><fac>Default</fac></ItemMaster></ItemMasterList> Here I want to change XML
I'm not entirely sure if I can do what I want here, but I
I work for a travel agency, they have a website, from here they want
I have string like order by o desc,b asc Here I want to replace
lets say I have a string that I want to split based on several
I want to convet int to string in objective c how to do that.
Hi I am working on XML file, here I want to give rights to
I want to run this query in Android Application : SELECT field1 FROM table1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.