我有以下method
:
public bool InsertUsername(string username)
{
string SQL = "Insert into [Users](Username, InsertDateTime) Values(@Username, datetime('now'));";
List<SQLiteParameter> pars = new List<SQLiteParameter>();
pars.Add(new SQLiteParameter("@Username", username));
return SQLiteUsernameDatabase.ExecuteNonQuery(SQL, pars);
}
ReSharper
告诉我使用collection initializer
代码List
。
问题:如何将SQLiteParameter添加到集合初始值设定项中?
答案 0 :(得分:1)
没关系,找到了解决方案:
public bool InsertUsername(string username)
{
string SQL = "Insert into [Users](Username, InsertDateTime) Values(@Username, datetime('now'));";
var pars = new List<SQLiteParameter> {new SQLiteParameter("@Username", username)};
return SQLiteUsernameDatabase.ExecuteNonQuery(SQL, pars);
}