Note:
This articleArticleI will record the mistakes I made in my personal development and write them out for criticism. I also hope that you will not make any mistakes I have made in the future.
You are welcome to publish your classic questions in the comments. I will update them in the article and enter your name.
I. string processing problems:
When a string is intercepted, an error may occur if you do not pay attention to it.
Example 1
If the category contains mens, gender is assigned male. If womens exists, gender is assigned female.
ErrorCodeAs follows:
View code
1 // This will never determine female, Because womens contains mens,
2 // At that time, it was miserable to be tested by mm. No more correct code, yesProgramAll members can be written. Be careful!
3 If (Gender = "" && Category. tolower (). indexof ( " Mens " ) > - 1 )
4 {
5 Gender = " Male " ;
6 }
7 Else If (Gender = "" && Category. tolower (). indexof ( " Womens " ) > - 1 )
8 {
9 Gender = " Female " ;
10 }
Example 2
Suppose we have 1 to 300 sites to manage, and now we need to process XXX If it is site 151, 152, 153, 154 and 155.
The error code is as follows:
View code
1 // As we all know that the regular expression processing efficiency is not high, this code will be called for hundreds of thousands of times, so string processing is used.
2 // However, at that time, we didn't take into account 1 and 51. During the test, we won't test site 1 and 51 due to this change, and almost had an online bug,
3 // I also let the test mm crazy once, but this is indeed my own fault, there is nothing so angry, please be careful later.
4 If ( " 151,152,153,154,155, " . Indexof (ddlcompany. selectedvalue + " , " ) >- 1 )
5 {....}
6 // The correct code is as follows:
7 If ( " , 151,152,153,154,155, " . Indexof ( " , " + Ddlcompany. selectedvalue + " , " ) >- 1 )
8 {....}
Example 3
When dealing with null strings:
View code
1 // This mistake is an idiot, but I still made it. I almost encountered a big problem. The more I am a programmer, the more I am an idiot.
2 String Username = Null ;
3 If ( String . Isnullorempty (username. Trim ())) // I want to remove a string of spaces.
4 {
5 ...
6 }
7 // Correct code
8 If ( String . Isnullorempty (username) | Username. Trim () = "" )
9 {
10 ...
11 }
Ii. Date Error
The time difference between the recent project calculation is calculated in C # and SQL respectively,
C #: (time 1-time 2). Days
SQL: diffdate (D, time 2, time 3)
As a result, the number of days is different. At that time, the self-test was not strong enough and I did not notice it. In the original SQL statement, 23:59:59 to, the result is 0 days.
But 23:59:59 to is a day... d represents only days to subtract, dizzy to death...
Improvement: refined to minute diffdate (MI, time 2, time 3)/1440
Iii. F5 and CTRL + F5
when studying CLR memory processing today, I saw an online article saying that you only need to add [loaderoptimization (loaderoptimization. multidomain)] you can add the self-written assembly to the shared domain, just like an int. I tried according to the method, but I finally asked the blogger, he said press Ctrl + F5, and I tried it. Later, I checked it online. Many of my friends said that F5 could not recognize []. I don't know why, but F5 could not recognize, in future debugging, pay attention to Ctrl + F5 (start directly without debugging). It is possible that the debugging has passed, but there is a problem with direct running.