2014-04-30 2 views
0

인터넷 연결을 확인하려고합니다. 엔드 포인트 (URL) 링크는 더문자열이 채워 졌는지 확인하십시오.

, 인터넷 연결이 있어야하지만이

1) 네트워크 연결

2)가 :이 검사에서 나는 두 가지를보고 싶어 해요 엔드 포인트 목적지 인 경우, 한 가지 작업을 수행해야하지만 인터넷 연결이없고 엔드 포인트 링크가 있거나없는 경우에는 다른 작업을 수행해야합니다.

나는 첫 번째 부분을 가지고 있는데, 연결이 없을 때 문자열이 채워지는지 확인하는 데 문제가 있습니다. 이 connection is true를 반환해야하지만 끊임없이 다시 connection is false을 반환

if(TestInternetConnection.connectionTrue.Equals(true) && string.IsNullOrEmpty(endPoint1)) 
{ 
    Debug.Log("connection is true"); 
} 

if(TestInternetConnection.connectionFalse.Equals(false) && string.IsNullOrEmpty(endPoint1) || endPoint1 != null) 
{ 
    Debug.Log("connection is false"); 
} 

이 지금까지 내 코드입니다. 내 문자열을 제대로 확인하려면 어떻게해야합니까?

+0

두 번째 조건은 (항상) 항상 사실입니다. 여러 bool 변수로 나누고 그 값을 디버그하여 봅니다 ... –

+0

'connectionFalse.Equals (false)'를'connectionFalse.Equals (true)'로 변경하려고합니다. – ermahgerd

답변

1

시도가) (넣어 두 번째 줄

을 확인하면서 코드에 우선 순위를 부여 ..이 시도
if(TestInternetConnection.connectionTrue.Equals(true) && string.IsNullOrEmpty(endPoint1)) 
{ 
    Debug.Log("connection is true"); 
} 

if(TestInternetConnection.connectionFalse.Equals(false) && (string.IsNullOrEmpty(endPoint1) || endPoint1 != null)) 
{ 
    Debug.Log("connection is false"); 
} 

그래서 먼저 확인됩니다 (string.IsNullOrEmpty (endPoint1) | | endPoint1! = null)) 다음 다른 부분을 확인하십시오.

+0

-1 어떤 OP가 확인하려고하는지 모르지만 두 번째 조건은 ** 항상 true ** :'endPoint'는 'null'이거나 비어있는 부분이 첫 번째 부분과 일치하고 'null'이 두 번째 조건과 일치하지 않습니다. . 당신이'A || ! A'. –

0

if(TestInternetConnection.connectionTrue.Equals(true) && string.IsNullOrEmpty(endPoint1)) 
{ 
    Debug.Log("connection is true"); 
} 
else if(TestInternetConnection.connectionFalse.Equals(false) && (string.IsNullOrEmpty(endPoint1) || endPoint1 != null)) 
{ 
    Debug.Log("connection is false"); 
} 
+0

그냥 그랬어 내 질문 (항상 다시 연결 false를 반환하는 것과 같은 결과) – N0xus

+0

위의 코드에서와 같이 같은 괄호에 마지막 두 조건을 넣으려고합니다. –

+0

-1 어떤 OP가 확인하려고하는지 모르지만 두 번째 조건은 ** 항상 true ** : 'endPoint'는'null '이거나 비어있는 부분이 첫 번째 부분과 일치하고'null '이 두 번째 조건과 일치하지 않습니다. . 당신이'A || ! A'. –

관련 문제