View Single Post
Old 11-15-2012, 05:38 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
You never substantiate store, you just declare it. It's not a datatype so it needs to be substantiated- you've only created a singleton
Code:
private Store store; //singleton
.......
//elsewhere
private someFxn()
{
  store = new Store();
  // now store is usable
}
which let's you do things like
Code:
private Store store;
.....
private someFxn()
{
  for(int i=0; i<10; i++)
  {
     store = new Store();
     using (store)
     {
         /// do something
     }
   }
}
without throwing an error (note idk what the java equivalent is to using in C#)

because if you did this
Code:
private Store store = new store();
.....
private someFxn()
{
  for(int i=0; i<10; i++)
  {
     using (store)
     {
         /// do something
     }
   }
}
it would go through the loop once, destroy it and then throw a null exception
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE

Last edited by alykins; 11-15-2012 at 05:40 PM..
alykins is offline   Reply With Quote