Calling Constructor from within the class.

  • Thread starter Thread starter Jeff Woodie
  • Start date Start date
J

Jeff Woodie

Just pull all of the code that "hydrates" your class out of the constructor
into it's own method. Then call that method from the constructor and
anywhere you want to "refresh" the class.

Jeff Woodie
 
Ummm...maybe I am missing the point but why don't you just Make a method
that reloads the data. You can then call that method from the constructor.
Maybe I am missing something but it would look like this....

class Foo
{
public Foo()
{
Refresh();
}
public void Refresh()
{
//load data into object.
}
}
 
Is it possible to call an objects constructor method from within the class
somehow? The class I have populates itself with data from a sqlServer
database when it is constructed, and I want to expose a method like
"refresh" which, essentially just "remakes" the object. However I can't do:

this = new ProjectCollection();

but "this" is read-only. Can an object modify itself in this way?

-D
 
Yes, I could do that. I guess my question was more theoretical. Why can't
an object do that to itself?

-D
 
Back
Top