The speed of forgetting is amazing

Source: Internet
Author: User

I haven't written my own classes for more than a month. I 've been using nbear's always doing some superficial work there. Today, I started to write the Code of my new project babystreet. I wrote a class that provides data and has no practical significance, it is the datacontent of the static LINQ to SQL. I wrote the following code:

  Public   static   class  dataprovider { Public   static  babystreetsqldata dB;  private   static   Object  _ lock =  New   Object  ();  Public  dataprovider () { If  (DB =  null ) { lock  (_ Lock) { // do this again to make sure dB is still null   If  (DB ==< SPAN class = "kwrd"> null ) {DB =  New  babystreetsqldata () ;}}}

This is an obvious error. It is interesting to write a constructor in a static class. I forgot to create an object like this.

 
Babystreetsqldata cb = dataprovider. dB;

Then, the object is copied to dataprovider. DB or directly referenced to dataprovider. DB. Write a function to test it:

Public ClassBaby {Public StringName {Get; set ;}Public StringAge {Get; set ;}PublicBaby (StringName,StringAge ){This. Name = Name;This. Age = age ;}}
 
Public Static ClassBabyprovider {Public StaticBaby Jesse =NewBaby ("Jesse","23");}
  class  program { static   void  main ( string  [] ARGs) {baby kucao = babyprovider. jesse; console. writeline ( "babyprovider. jesse information: "); console. writeline (babyprovider. jesse. name); console. writeline ( "kucao information:" ); console. writeline (kucao. name); kucao. name =  "kucao" ; console. writeline ( "============================ ============ " ); console. writeline ( "babyprovider. jesse information: "); console. writeline (babyprovider. jesse. name); console. writeline ( "kucao information:" ); console. writeline (kucao. name); console. readline () ;}

The running result is:

Babyprovider. Jesse information:
Jesse
Kucao information:
Jesse
========================================================== =
Babyprovider. Jesse information:
Kucao
Kucao information:
Kucao

It seems to be referenced. I forgot a lot of things. I'm depressed. Do it.

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.