.net - What is the best way to create a class object and reuse it in C#? -


im new c# , have c# application can print bills. in case use class (billprint) create bill. after open application print bills contentiously, still application working fine need know way of doing correct or not or if wrong how fix. use bill class use following code,

list<receipt> order;             order = loadreceiptdata();             sessiondata.setbillamount();              billprint bill = new billprint(order, sessiondata.lastbillamout, sessiondata.tabel, 1); 

is necessary check bill object exists or not before creating ? , how that.

you've got couple of options.

1) create new bill each time, e.g. when user clicks printbill(). this

private void printbill(object sender, eventargs e) {     billprint bill = new billprint(...); } 

2) if having 1 important @ implementing singleton pattern , updating bill before print each one. this

public class billprint {    private static billprint instance;     private billprint() {}     public static billprint instance    {              {          if (instance == null)          {             instance = new billprint();          }          return instance;       }    }     public void updatebill(...)    {         // update bill    } }  

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -