如何使用内联C#的,如果不是使用长C#的if语句

如何,如果减少的代码行数,这些类型的编码如何使用内联C#的,如果不是使用长C#的if语句

 if (string.IsNullOrEmpty(txtpictext.Text)) 

{

Cmd.Parameters.AddWithValue("@pictext", DBNull.Value);

}

else

{

Cmd.Parameters.AddWithValue("@pictext, txtpictext.Text);

}

Conn.Open();

Cmd.ExecuteNonQuery();

回答:

的您要使用的三元操作语句中使用单行?:

Cmd.Parameters.AddWithValue("@pictext, string.IsNullOrEmpty(txtpictext.Text) 

? DBNull.Value

: txtpictext.Text);

Conn.Open();

Cmd.ExecuteNonQuery();

像这样。

回答:

string assignedValue = string.Empty; 

assignedValue = string.IsNullOrEmpty(txtpictext.Text) ? DBNull.Value : txtpictext.Text ;

Cmd.Parameters.AddWithValue("@pictext", assignedValue);

Conn.Open();

Cmd.ExecuteNonQuery();

以上是 如何使用内联C#的,如果不是使用长C#的if语句 的全部内容, 来源链接: utcz.com/qa/262624.html

回到顶部