I want to add column from one table to another. Here, colName is string variable, which is extracted from hard-coded parameter provided by developer. so chances of colName being incorrect is very less. I want to avoid exception raised due to wrong colName.
Which is the best way to achieve same? I thought of two options below.
if(_table.Columns.Contains(colName))
{
AddColumnToTable(_table.Columns[colName]);
}
OR
try
{
AddColumnToTable(_table.Columns[colName]);
}
catch { }
Aucun commentaire:
Enregistrer un commentaire