Static use to pay attention to the place

Source: Internet
Author: User

protected static string headimg = String. Empty;

Use static here, if you write like this
Object himg = DBUtility.DbHelperSQL.GetSingle (HSTR);
       if (himg! = null) {headimg = "http://www.16njl.com" + convert.tostring (himg); }
Assign a value to Headimg, there is assignment, no data is not processed headimg
This will cause an error, when you do not re-assign the value of the assignment headimg, the value of headimg will be saved, even if you re-login, the value as long as it has not been re-assigned to exist (there may be a time limit, but a long time), the next account does not change headimg Value, an error occurs with the headimg of the previous account.

   protected static string headimg = string. Empty;        protected void page_load (Object sender,  eventargs e)         {
}
This method of static is not changed because of the account headimg== String. Empty; The value of the headimg does not change unless the value is re-assigned within the function.

So be sure to write this way:
  object himg = dbutility.dbhelpersql.getsingle (HSTR);                 if  (himg != null)                  {                     headimg =   "http://www.16njl.com"  + convert.tostring (himg);                 }                 else                 {                      headimg =  ""; Remember to re-assign the value         &Nbsp;       } 

or remove the static.

Static use to pay attention to the place

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.