C#
c#에서 null string처리 string.IsNullOrEmptuy(문자)
saltdoll
2017. 8. 25. 00:15
반응형
string에 null 이거나 '' (Empty String)일때, 처리하지 않게 하려면, string.IsNullOrEmpty()를 사용하면 됩니다.
if (!string.IsNullOrEmpty(row["TIP_ADJUST"].ToString()))
{
_tip_adjust_total += Convert.ToDecimal(row["TIP_ADJUST"]);
}
C#에서 Null과 Empty String 차이
Empty String |
string s = ""; //System.String 객체에 zero문자만을 가진것. |
Null String |
string s = null; int len = s.Length;; // NullReferenceExcption 발생(throw). |
C#의 null 체크하기
string str =null ; if (str == null) {
MessageBox.Show("String is null"); }
C#에서 null 또는 string.Empty 체크하기
string str =null; if (string.IsNullOrEmpty(str)) {
MessageBox.Show("String is empty or null"); }
참고:
How to C# String Null http://csharp.net-informations.com/string/string-null-cs.htm (예제가 잘 나와있습니다.)
반응형