我是 C# 的新手,
我想构建查询字符串,我做了一些条件,每个条件都在 where 子句中添加另一个条件
我想要这样的东西:
// BUILD SELECT QUERY
string where = "";
string[] where_arr = new string[];
if (condition1)
{
where_arr[index++] = " field = 5 ";
}
if (condition2)
{
where_arr[index++] = " field2 = 7 ";
}
if (where_arr.Count>0)
where = " where" + String.Join(" and ", where_arr);
string sql = "select count(*) as count from mytable " + where;
但我不确切知道如何声明所有变量,如where_arr