久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么連接空字符串有效但調(diào)用“null.ToString()&

Why is it Valid to Concatenate Null Strings but not to Call quot;null.ToString()quot;?(為什么連接空字符串有效但調(diào)用“null.ToString()無(wú)效?)
本文介紹了為什么連接空字符串有效但調(diào)用“null.ToString()"無(wú)效?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問題描述

這是有效的 C# 代碼

This is valid C# code

var bob = "abc" + null + null + null + "123";  // abc123

這不是有效的 C# 代碼

This is not valid C# code

var wtf = null.ToString(); // compiler error

為什么第一條語(yǔ)句有效?

Why is the first statement valid?

推薦答案

第一個(gè)工作的原因:

來(lái)自 MSDN:

在字符串連接操作中,C# 編譯器將空字符串視為空字符串,但不會(huì)轉(zhuǎn)換原始空字符串的值.

In string concatenation operations,the C# compiler treats a null string the same as an empty string, but it does not convert the value of the original null string.

有關(guān)的更多信息+ 二元運(yùn)算符:

當(dāng)一個(gè)或兩個(gè)操作數(shù)都是字符串類型時(shí),二元 + 運(yùn)算符執(zhí)行字符串連接.

The binary + operator performs string concatenation when one or both operands are of type string.

如果字符串連接的操作數(shù)為空,則替換為空字符串.否則,通過調(diào)用從類型對(duì)象繼承的虛擬 ToString 方法,將任何非字符串參數(shù)轉(zhuǎn)換為其字符串表示.

If an operand of string concatenation is null, an empty string is substituted. Otherwise, any non-string argument is converted to its string representation by invoking the virtual ToString method inherited from type object.

如果 ToString 返回 null,則替換為空字符串.

If ToString returns null, an empty string is substituted.

第二個(gè)錯(cuò)誤的原因是:

null(C# 參考) -null 關(guān)鍵字是表示空引用的文字,不引用任何對(duì)象.null 是引用類型變量的默認(rèn)值.

null (C# Reference) - The null keyword is a literal that represents a null reference, one that does not refer to any object. null is the default value of reference-type variables.

這篇關(guān)于為什么連接空字符串有效但調(diào)用“null.ToString()"無(wú)效?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應(yīng)該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語(yǔ)法?)
How to set null value to int in c#?(如何在c#中將空值設(shè)置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時(shí)如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 亚洲 欧美 日韩 在线 | 日日人人| 玖玖玖在线 | 全免费a级毛片免费看视频免 | 在线精品亚洲欧美日韩国产 | 精品一区二区在线视频 | 国产精品色婷婷久久58 | 综合久 | 一级大黄色片 | 欧美日韩视频在线播放 | 天天干天天爱天天爽 | 成人自拍视频 | 久操伊人 | 亚洲播放一区 | 日本久久久一区二区三区 | 国产99精品 | 久久久蜜桃 | 日本不卡高字幕在线2019 | 91在线最新 | 国产日韩精品一区 | 久久综合一区二区 | 日韩精品一区二区三区 | 欧美1区2区 | 黑人久久久 | 成年人在线观看视频 | 日韩在线电影 | 色秀网站 | 欧美 日韩 中文 | 日韩精品亚洲专区在线观看 | 欧美一区二区三区 | 久草电影网| 国产亚洲精品久久久优势 | 福利网址| 欧美一区二区三区在线观看视频 | 亚洲综合大片69999 | 91精品国产乱码久久蜜臀 | 偷拍自拍网址 | 日本不卡一区二区三区在线观看 | 黄网站涩免费蜜桃网站 | 精品成人av | 亚洲精品欧美 |