Why is it when I do this:
private void button18_Click(object sender, EventArgs e)
{
string uri1 = "http://localhost:8000/Service/GetMessage/{anything}";
string tagUri = uri1.Replace("{anything}", textBox21.Text);
XDocument xDoc = XDocument.Load(tagUri);
var MessageID = xDoc.Descendants("Message")
.Select(n => new
{
MessageID = n.Element("MessageID").Value,
})
.ToString();
textBox1.Text = MessageID;
I get this really strange output?
System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,<>f__AnonymousType7`1[System.String]]
But yet when I change ToString to ToList and use:
dataGridView10.DataSource = MessageID;
It displays it correctly? Really struggling to find out a way to take my incoming GET request to string?
Your LINQ query is getting a collection by nature of the call to
.Descendants. If there’s only one, you can use a.Single()or.First()or.FirstOrDefault()to get the only (or First) item in the list.Then it would be
Though you more likely want to do something like this:
But I’m somewhat guessing, as I don’t know the format or content of your XML.