By moving with C # I have found that a new instance can be created without storing it inside an identifier.
I understand that these statements only work with classes because of the need to invoke some method within them, but does this instance always remain in memory?
Example, suppose I have the following class:
class Printer
{
private string _internal;
public void Print() { Console.WriteLine(_internal); }
public Printer(string s) { _internal = s; }
}
And I call from:
static void Main()
{
new Printer("Hola Mundo!").Print(); // Imprime "Hola Mundo"
}
The type object Printer
that was instantiated will always remain in memory until the execution of the program ends?