Today, a colleague asked me a piece of code written by a company employee who has left the company. It looks a little strange. The Code is as follows:
/// <Summary> /// return the request // </Summary> /// <Param name = "name"> </param> /// <Param name = "encrypt"> encryption </param> // <returns> </returns> Public static string request (string name, bool encrypt) {httprequest Req = httpcontext. current. request; string STR = req. form [name]? Req. querystring [name]? ""; If (encrypt) {return encryptstring (STR);} STR = system. Web. httputility. urldecode (STR, system. Text. encoding. utf8); Return STR ;}
Where is it?
It's strange that this string STR = Req. Form [name]? Req. querystring [name]? ""; In ??
I found it hard to understand. Later I checked the information on the Internet and explained it as follows:
"Single question mark-used to assign null to the variable (INT type) when setting the initial value, rather than 0!
Double question mark-used to determine and assign values. First, judge whether the current variable is null. If yes, you can assign a new value. Otherwise, skip this step !"
Netizen Napoleon Article http://www.mapviews.cn /? P = 200 explained. The demo he gave is as follows:
Public Int? Para; // public int para; if this line is not commented out and the previous line is commented out, an error will be reported below! Public int PAR () {return this. Para ?? 0 ;}
For such an efficient writing method, you must take notes and share them with friends!