前面先單引,再雙引;變量放中間,+號放左右;后面與前面配對,先雙引,再單引。
如下:
' "+變量+" '
例:
寫法1:
string sql = " select * from t_admin where Uid='"+textBox_username+"' and pwd='"+textBox_userpwd+"' ";
寫法2:
string sql = $" select * from t_admin where Uid='{textBox_username}' and pwd='{textBox_userpwd}' ";
還有一種使用占位符的寫法就不在這里說了,我是傾向於用第二種寫法的,簡單直觀明了方便。