如何使用单行if语句减少这些编码的代码行数
if (string.IsNullOrEmpty(txtpictext.Text))
{
Cmd.Parameters.AddWithValue("@pictext", DBNull.Value);
}
else
{
Cmd.Parameters.AddWithValue("@pictext, txtpictext.Text);
}
Conn.Open();
Cmd.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
小智 5
你想使用三元运算符?:
Cmd.Parameters.AddWithValue("@pictext, string.IsNullOrEmpty(txtpictext.Text)
? DBNull.Value
: txtpictext.Text);
Conn.Open();
Cmd.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)
像这样.