tags:

views:

9

answers:

1

Hi,

I have written some code like this.

    public void Preview()
    {            
        _printTemplate = new MarineBunkerPrintTemplate();           
        UpdateInfo();
        _printTemplate.SetInfo();
    }

Here whenever i call Preview() method i am creating new object of _printTemplate, Instead of i have to check existing object available or not avilable means i have to delete existing and i have to create new and use or some other way.

A: 

I don't know the context in which it is used, but how about:

public void Preview() 
{   
   if (_printTemplate == null)
   {   
        _printTemplate = new MarineBunkerPrintTemplate();            
   }
    UpdateInfo(); 
    _printTemplate.SetInfo(); 
}
Mitch Wheat