3
Answers

How to Update Current Instance of object

Bati

Bati

16y
2.7k
1

Hello,

I have a method that populates my class by loading an XML:

public class MyClass

{

public void LoadXML(string xmlFilePath)

{

MyClass myObj = new MyClass();

myObj = (MyClass)s.Deserialize(reader); // Deserialize and populate my object from an XML file

//myObj is properly filled with data

return;

}

}

Now I just want to call this method from another class, so I simply have:

MyClass testObj = new MyClass();

testObj.LoadXML("myFile.xml");

testObj --> is EMPTY after the function returns...

Here is my question:

How can I make my current instance (testObj) filled with the data... without having to RETURN an object from my method ? (I want my method to return void)

I want it to work similarly to the NET XmlDocument class:

XmlDocument doc = new XmlDocument()

doc.Load(..) //doc is filled with data

How can I do the same thing? Dows Anybody know how to do this?

Thank you very much in advance for any help

Cheers,

 

Answers (3)