string a = "test";
if(a==true){
label.text = "true";
}
с таким кодом пишет Неявное преобразование типа "bool" в "string" невозможно
Stack Overflow на русском — это сайт вопросов и ответов для программистов. Присоединяйтесь! Регистрация займёт не больше минуты.
Присоединиться к сообществуstring a = "test";
if(a==true){
label.text = "true";
}
с таким кодом пишет Неявное преобразование типа "bool" в "string" невозможно
Если касается только строки, то можно использовать IsNullOrEmpty
if (String.IsNullOrEmpty(str))
Console.WriteLine("is null or empty");
пример из доков:
class Sample
{
public static void Main()
{
string s1 = "abcd";
string s2 = "";
string s3 = null;
Console.WriteLine("String s1 {0}.", Test(s1));
Console.WriteLine("String s2 {0}.", Test(s2));
Console.WriteLine("String s3 {0}.", Test(s3));
}
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);
}
}
// The example displays the following output:
// String s1 ("abcd") is neither null nor empty.
// String s2 is null or empty.
// String s3 is null or empty.
if (a!=null)
? илиif (!string.IsNullOrEmpty(a))
? – tym32167 26 ноя '17 в 15:04null
отсутствием значения, но вообще-то это такое же значение, как и другие. – VladD 26 ноя '17 в 15:06