I am new to .net. I have a form in which there are two comboboxes cbProduct and cbBrandName and also a label lblPrice.
I am trying to implement the below code but it is showing blue scribbles to &&.
(Error: operator ‘&&’ cannot be applied to operands of type ‘lambda expression’ and ‘lambda expression’)
I tried the below code: (not working)
lblPrice.Text = string.Empty;
lblPrice.Text = doc.Descendants("items"
).Where((x => x.Element("productname"
).Value.Equals(cbProduct.SelectedItem.ToString())) && /*blue scribbles to '&&'*/
(y => y.Element("brandname").Value.Equals(cbBrandName.SelectedItem.ToString()
))).Select(k => k.Element("price"
).Value).ToString();
My other question is that i want to make the selected values of cbProduct as distinct. The below code takes all the values instead of distinct values:
cbProduct.Items.AddRange(doc.Descendants("items"
).Select(x => x.Element("productname").Value
).ToArray<string>());//adds all products
cbProduct.SelectedIndex = 0;
giving any one answer is ok
Please assist me
Thanks in advance
For the first question, it looks like you just want to select the one price. This code will work, assuming that the item is found by the
.Single(). It will throw otherwise, in which case you should use.SingleOrDefault()and check for null on the found item.For the second question, you need to close off your
.Selectwith a bracket, then you can call.Distinct()and.ToArray()to filter to distincts and project the result tostring[]. I’ve also thrown an.OrderBy()in there, as there’s nothing more annoying than a ComboBox in a random order. Try this: