Object class 의 Empty 체크하기!

[출처 ㅣ https://msdn.microsoft.com/ko-kr/library/system.string.isnullorempty(v=vs.110).aspx]

 

 

public object Result{ get; private set; }

 

Result = mySqlCommand.ExecuteScalar();

 

// 이 ExecuteScalar 쿼리를 했을때 DB에 저장된 데이터가 없어서 Result 값이 empty 인 상황이었다.

 

 

그래서 해결법은

 

string str = readReq.Result.ToString()

 

 if (str.Equals(""))
 {
    Debug.Log("MaxEmployeeNumber is not existence");
    MaxEmployeeNumber = 0;
    Debug.Log("MaxEmployeeNumber :" + MaxEmployeeNumber);
 }
 else
 {
     MaxEmployeeNumber = (long)readReq.Result;
     Debug.Log("MaxEmployeeNumber:" + MaxEmployeeNumber );
 }

 

후..!

 

 

+ String.IsNullOrEmpty 메서드 를 사용하여 코드를 바꿔보았다.

 

매개 변수가 null 이거나 빈문자열("")이면 true 고

아니면 false 이다.

 

쓰는법

 

string.IsNullOrEmpty(스트링변수)

 

public static String Test(string s)

{   if (String.IsNullOrEmpty(s))
        return "is null or empty";
    else
        return String.Format("(\"{0}\") is neither null nor empty", s);
    }