I want to read a xml file and load as list and look for the value during the form load. How can i read the file and get it as a list???
The Xml file:
<?xml version="1.0" encoding="utf-8"?>
<Types>
<Type>t1-p2</Type>
<Type>t1-k1</Type>
<Type>t2-s2</Type>
</Types>
Class File:
class Testtypes
{
public string Type;
public static List<Testtypes> getTypes()
{
XDocument doc = XDocument.Parse("test.xml");
var q = doc.Descendants("Type").ToList();
return getTypes.();
}
}
Firstly, I would not have a public field. At least use a property. I’d also rename the class to something a little more meaningful. But you can change your code to:
Or given that you’ve only got a string, you could avoid creating your own type: