开发者

Trouble with ternary operator/shorthand if

开发者 https://www.devze.com 2022-12-14 08:45 出处:网络
if ((file.Exists) ? lblresults.Text = \"the file is there\" : lblresults.Text = \"the file is not there\");
if ((file.Exists) ? 
lblresults.Text = "the file is there" : 
lblresults.Text = "the file is not there");

I keep getting the error st开发者_JAVA百科ating cannot implicitly convert string to bool

any help would be great, thanks.


try this:

lblResults.Text = file.Exists ? "the file is there" : "the file is not there";

Basically you don't need the if.


It expects a bool back. Try this:

lblResult.Text = ((file.Exists) ? "the file is there" : "the file is not there");
0

精彩评论

暂无评论...
验证码 换一张
取 消