stringæ¯å¼ç¨ç±»åï¼
string str = null 没æå建å
å空é´ï¼strä¸åæ¾çæ¯ç©ºå¼ç¨æéï¼
string str = "" å建äºå
å空é´ï¼strä¸åæ¾çæ¯æåå ä¸çæéã
ç®åå°è¯´ï¼
string str ="";
ç»ä½ ä¸å¼ ç½çº¸ï¼
string str = null;
è¿ç½çº¸ä¹æ²¡æã
string.Emptyå°±ç¸å½äº""
ä¸è¬ç¨äºå符串çåå§å
æ¯å¦ï¼
string a;
Console.WriteLine(a);//è¿éä¼æ¥éï¼å 为没æåå§åa
èä¸é¢ä¸ä¼æ¥éï¼
string a=string.Empty;
Console.WriteLine(a);
æè
ç¨äºæ¯è¾ï¼
if(a=="")
if(a==string.Empty)
ä¸é¢ä¸¤å¥æ¯ä¸æ ·çææã
string.Emptyä¸åé
åå¨ç©ºé´
""åé
ä¸ä¸ªé¿åº¦ä¸ºç©ºçåå¨ç©ºé´
æ以ä¸è¬ç¨string.Empty
为äºä»¥å跨平å°ï¼è¿æ¯ç¨string.empty
å¨ C# ä¸ï¼å¤§å¤æ°æ
åµä¸ "" å string.Empty å¯ä»¥äºæ¢ä½¿ç¨ãæ¯å¦ï¼
string s = "";
string s2 = string.Empty;
if (s == string.Empty) {
//
}
ifè¯å¥æç«
å¤å®ä¸ºç©ºå符串çå ç§åæ³ï¼æç
§æ§è½ä»é«å°ä½ç顺åºæ¯ï¼
s.Length == 0 ä¼äº s == string.Empty ä¼äº s == ""
æ¨å
³äºString.EmptyåNullçé®é¢æ¯è¿æ ·çï¼è¿ä¸¤ä¸ªé½æ¯è¡¨ç¤ºç©ºå符串ï¼å
¶ä¸æä¸ä¸ªéç¹æ¯string str1= String.Emptyå string str2=null çåºå«ï¼è¿æ ·å®ä¹åï¼str1æ¯ä¸ä¸ªç©ºå符串ï¼ç©ºå符串æ¯ä¸ä¸ªç¹æ®çå符串ï¼åªä¸è¿è¿ä¸ªå符串çå¼ä¸ºç©ºï¼å¨å
åä¸æ¯æåç¡®çæåçï¼string str2=null,è¿æ ·å®ä¹åï¼åªæ¯å®ä¹äºä¸ä¸ªstring ç±»çå¼ç¨ï¼str2并没ææåä»»ä½å°æ¹ï¼å¨ä½¿ç¨åå¦æä¸å®ä¾åçè¯ï¼é½å°æ¥éãtextBox1.Textçå¼ä¸ºé¶é¿åº¦å符串 ""ã
温馨提示:答案为网友推荐,仅供参考