N0xus
N0xus

Reputation: 2724

Checking if a string is filled or not

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

Answers (2)

Firdavs Kurbonov
Firdavs Kurbonov

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

Ravi Patel
Ravi Patel

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

Related Questions