using System.Collections.Generic;
static string MontarSqlComCondicoes(string tabela, string c1, string c2, bool and)
var condicoes = new List<string>();
var sql = new StringBuilder();
sql.Append("select * from")
if (!string.IsNullOrWhiteSpace(c1))
if (!string.IsNullOrWhiteSpace(c2))
if (and) sql.Append(string.Join(" and ", condicoes.ToArray()));
else sql.Append(string.Join(" or ", condicoes.ToArray()));
public static void Main()
var sql = MontarSqlComCondicoes("pessoa", "nome = @nome", "idade > @idade", true);