C# 将集合初始值设定项与insert语句一起使用
我有以下C# 将集合初始值设定项与insert语句一起使用,c#,resharper,collection-initializer,C#,Resharper,Collection Initializer,我有以下方法: 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 SQL
方法
:
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);
}
public bool InsertUsername(字符串用户名)
{
string SQL=“插入[用户](用户名,插入日期时间)值(@Username,datetime('now');”;
List pars=新列表();
添加(新的SQLiteParameter(“@Username”,Username));
返回SQLiteUsernameDatabase.ExecuteNonQuery(SQL,pars);
}
ReSharper
告诉我对PAR列表使用集合初始值设定项
问题:如何将SQLiteParameter添加到集合初始值设定项?无需担心,已找到解决方案:
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);
}
public bool InsertUsername(字符串用户名)
{
string SQL=“插入[用户](用户名,插入日期时间)值(@Username,datetime('now');”;
var pars=新列表{new SQLiteParameter(“@Username”,Username)};
返回SQLiteUsernameDatabase.ExecuteNonQuery(SQL,pars);
}
请将您的解决方案作为答案发布,并在可能的情况下接受。否则,你的问题看起来没有答案,实际上它不再需要答案了。谢谢你的建议!啊哈,正在寻找它,在左边找到了“创意灯”。