Probably a stupid question, but I'm quite new to the whole "get-and-set-property"-kind of programming;
I keep getting a compiling-error on this part of my code;
private string _File = "Session.xml";
private XmlDocument XmlDoc
{
get
{
XmlDocument _Doc = new XmlDocument();
return _Doc.LoadXml(_File);
}
}
private XmlElement XmlRoot
{
get
{
return XmlDoc.DocumentElement;
}
}
How come? I can't explain that to myself as I don't even see any implicit conversions...
The problem is this line:
return _Doc.LoadXml(_File);
You're trying to return a value from a method that has a return type of void.
Try this instead:
private XmlDocument XmlDoc
{
get
{
XmlDocument _Doc = new XmlDocument();
_Doc.LoadXml(_File);
return _Doc;
}
}
This code is your problem:
return _Doc.LoadXml(_File);
The LoadXml method has a return type of void, as the method does not return any value, instead populating the XmlDocument instance from the file path specified.
To fix your problem, simply change your property to this:
private XmlDocument XmlDoc
{
get
{
XmlDocument _Doc = new XmlDocument();
_Doc.LoadXml(_File);
return _Doc;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With