检查字符串是否已填满

时间:2014-04-30 09:20:36

标签: c# string

我正在尝试检查互联网连接。在这个检查中,我想看到两件事:

1)是否有网络连接

2)是否有端点(url)链接

如果有互联网连接,但没有端点目的地,它应该做一件事,但如果没有互联网连接,如果它有端点链接,它应该做其他事情。

我已经完成了第一部分工作,但是我没有在没有连接时检查我的字符串是否已填满的问题。到目前为止,这是我的代码:

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");
}

这应该返回connection is true,但它会不断返回connection is false。我怎样才能正确检查我的字符串?

2 个答案:

答案 0 :(得分:1)

尝试使用put()在检查第二行时优先考虑代码

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))然后检查其他部分。

答案 1 :(得分: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");
}
相关问题