After reading your comment that saving and opening a serialized version of your object is what you really want to do I provide this answer.
The Save
method is always the same:
class Car {
public void Save(String fileName) {
// Serialize the fields of the current instance to the file.
}
}
To initialize a new instance from the serialized data you can use a constructor:
class Car {
public void Car(String fileName) {
// Initialize a new instance from the serialized data in the file.
}
}
Another option is to provide a static factory method:
class Car {
public static Car Open(String fileName) {
var car = new Car();
// Initialize the new instance from the serialized data in the file.
return car;
}
}
The main point is that the "Open" method is not a method on a Car
instance. It should either be a constructor or a static method. Then you don't have to "internally set an object equal to a reference" (which isn't possible anyway).
In some ways the line of thought you have presented in your question is similar to Prototype-based programming. However, C# is a class-based language as opposed to a prototype-based language.