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.