C # Basics of static (popular interpretation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.