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

檢查空值的最短方法,如果不是,則分配另一個

Shortest way to check for null and assign another value if not(檢查空值的最短方法,如果不是,則分配另一個值)
本文介紹了檢查空值的最短方法,如果不是,則分配另一個值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在從數據庫中提取 varchar 值并想設置 string 如果它們是 null 我將它們分配為">.我目前正在這樣做:

I am pulling varchar values out of a DB and want to set the string I am assigning them to as "" if they are null. I'm currently doing it like this:

if (string.IsNullOrEmpty(planRec.approved_by) == true)
  this.approved_by = "";
else
  this.approved_by = planRec.approved_by.toString();

似乎應該有一種方法可以在一行中執行此操作,例如:

There seems like there should be a way to do this in a single line something like:

this.approved_by = "" || planRec.approved_by.toString();

但是我找不到最佳方法來做到這一點.有沒有更好的方法或者我有什么最好的方法來做到這一點?

However I can't find an optimal way to do this. Is there a better way or is what I have the best way to do it?

推薦答案

試試這個:

this.approved_by = IsNullOrEmpty(planRec.approved_by) ? "" : planRec.approved_by.toString();

您也可以像其他人所說的那樣使用空合并運算符 - 因為沒有人給出適用于您的代碼的示例,這里是一個:

You can also use the null-coalescing operator as other have said - since no one has given an example that works with your code here is one:

this.approved_by = planRec.approved_by ?? planRec.approved_by.toString();

但此示例僅適用于 this.approved_by 的可能值與您希望將其設置為的潛在值之一相同.對于所有其他情況,您將需要使用我在第一個示例中展示的條件運算符.

But this example only works since a possible value for this.approved_by is the same as one of the potential values that you wish to set it to. For all other cases you will need to use the conditional operator as I showed in my first example.

這篇關于檢查空值的最短方法,如果不是,則分配另一個值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

How to check if String is null(如何檢查字符串是否為空)
Equals(item, null) or item == null(Equals(item, null) 或 item == null)
Overriding == operator. How to compare to null?(覆蓋 == 運算符.如何與空值進行比較?)
What does the question mark in member access mean in C#?(成員訪問中的問號在 C# 中是什么意思?)
The || (or) Operator in Linq with C#(||(或)C# 中的 Linq 運算符)
C# null coalescing operator equivalent for c++(C# 空合并運算符等效于 C++)
主站蜘蛛池模板: 国产精品一级 | 一级欧美一级日韩片免费观看 | 久久久这里只有17精品 | 亚洲一区二区三区免费在线 | 国产一区精品 | 久久国产一区二区三区 | av免费在线播放 | 成人精品在线视频 | 在线国产一区二区 | 中文字幕av一区二区三区 | www.蜜桃av | 中文字幕一区二区三区在线观看 | 久久一区二区三区四区 | 久久精品国产久精国产 | 精品免费 | 一区二区三区视频在线观看 | 日韩激情在线 | www久久爱| 国产在线精品一区二区三区 | 国产精品日韩欧美 | 日韩精品色网 | 国产精品美女久久久久aⅴ国产馆 | 欧美一区二区三区久久精品视 | 91精品国产综合久久久动漫日韩 | 久久亚洲精品视频 | 久久久精彩视频 | 欧美一区二区三区久久精品 | 精品美女久久久 | 国产在线观看不卡一区二区三区 | 国产网站在线免费观看 | 日韩三级在线 | 欧美一区免费 | 日日操网站 | 日本一区二区三区在线观看 | 亚洲三区在线播放 | 成人av网站在线观看 | 国产精品免费小视频 | 一级在线观看 | 一区二区三区四区免费观看 | 麻豆毛片| 在线免费观看一区二区 |