如何在C#中使用三元运算符 [英] How to use ternary operator in C#

查看:297
本文介绍了如何在C#中使用三元运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int number = 5;



  • number 等于5时,写true

  • 数字不等于5时,写错

    • when the number is equal to 5, write true
    • when the number is not equal to 5, write false
    • 我该如何

      推荐答案

      int five = 5;
      string answer = five == 5 ? "true" : "false";
      

      我看到您想使用它在ASP.NET中写出值, answer 字符串将保存您想要的值,请根据需要使用它。

      I see that you want to use this to write the values out in ASP.NET, the answer string will hold your desired value, use that as you please.

      这篇关于如何在C#中使用三元运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆