我有一个简单的条件,想用?:
关键字来实现它,但编译器不允许我这样做。这是确切的样本
// in asp page decleration
<ajaxtoolkit:FilteredTextBoxExtender id="ftbeNumeric" runat="server" TargetControlID="textbox1" FilterType="Numbers" />
<asp:TextBox ID="textbox1" runat="server" />
// in code behind
decimal x = textbox1.Text != string.IsNullOrEmpty ? Convert.ToDecimal(textbox1.Text) : 0;
我也试试这个
// in code behind
decimal x = Convert.ToDecimal(textbox1.Text) != 0 ? Convert.ToDecimal(textbox1.Text) : 0;
这些样本中的第一个有错误。
如何用?:
关键字定义这个?并注意textbox
.text` 可能为空。