Working on a application which reads some values from an customers.xml file to UI.
Linq to xml code:
var Settings = (from e in customer.Descendants("appSettings")
from kvpair in e.Elements("Name")
select new
{
Name = kvpair.Attribute("Zip").Value,
Node = kvpair
}).ToDictionary(x => x.Name, y => y);
txtFName.Text==Settings["CustomerA"].Node.attribute("value").Value;
txtLName=Settings["CustomerB"].Node.attribute("value").Value;
I am able to get the values into GUI from XMl file by the above code.
My question is when i comment out any element or data from xml file of a particular customer i get the error “the given key is not present in the dictionary”
How do i dynamically check whether a key exists in dictionary if then only read that value or else got to the next value ?
EDIT:
You can loop through keys accessing Keys property collection:
Also you can use LINQ to filter out what you need: