Reputation: 2724
I'm trying to check for an internet connection. In this check I'm wanting to see two things:
1) is there a network connection
2) is there an endpoint (url) link
Should there be an internet connection, but no endpoint destination, it should do one thing, but if there is no internet connection and if it has an endpoint link or not, it should do something else.
I've got the first part working, I'm just having issue with checking if my string is filled or not when there isn't a connection. This is my code so far:
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");
}
This should be returning connection is true
but its constantly return back connection is false
. How can I get it properly check my string?
Upvotes: 0
Views: 243
Reputation: 1252
Try to put () to give priority in your code while checking second line
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");
}
So firstly will be checked (string.IsNullOrEmpty(endPoint1) || endPoint1 != null)) and then checked other parts.
Upvotes: 1
Reputation: 463
Try this..
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");
}
Upvotes: 0