Assuming this dummy method to get data from the database, let's say SQL Server:
public List<DadosDTO> ObterDados()
{
try
{
comand = connectionFactory.CreateCommand();
comand.CommandText = "SELECT intDado, stringDado, dateDado, doubleDado FROM TB_DADOS";
comand.Connection = connection;
dataReader = comand.ExecuteReader();
List<DadosDTO> LstDados = new List<DadosDTO>();
while (dataReader.Read())
{
DadosDTO dados = new DadosDTO();
//Popular variáveis aqui.
LstDados.Add(dados);
}
return LstDados;
}
catch (Exception)
{
throw;
}
finally
{
connection.Close();
}
}
Is there a recommended standard for popularizing variables? A more correct and optimized way? Is this way that I structured the method is the best or is there another way?
My question is to learn the best way to do it and why, so if anyone knows and can explain ...