For this thing in school only the variables declared with static are owned by the class and are not instantiated, for example:
1 Public class hehe 2 {3 public static void drink ()4 { 5 // drink lemon black tea 6 }7 }
Called in the case of a static modification:
Hehe. Drink ();
To invoke without a static modifier:
Hehe h=new hehe ();
H.drink ();
As you can see, the above is easier to write, except for this benefit? And, of course, I found a problem when I was doing webform.
I want to import Excel into the dataset, and then DS save the data
DataSet ds=getexcelxxxxxxxxxxxxxxxx ();
Then click the button "list data" to loop the DS output,
Then click the button "Import data" loop DS Insert Database, but in this process found that the "import data" when the DS is gone, error DS is not instantiated.
Later know that the original click on the "List data" button, the page refreshed , so the variables are empty, the error is not instantiated, because it has no value. This involves the life cycle of the problem, want to know can go to Baidu to see, I rookie one, so advanced things do not understand, can only say simple things ....
Is there any way to save the value in the case of page refresh ?
First: Define a static modified variable , such as when declaring this DS: Static DataSet Ds=new DataSet ();
Second: Use a Session to save , for example, before the page refreshes the value: session["DS"]=DS;
static persists in memory until the end of the program, so the page refreshes and it persists.
Static C # Basics (Popular explanation)