开发者

Trouble with ternary operator/shorthand if

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜