In the below code, the statement 1 throws casting exception. I am wondering why isnt it unboxing?
The statement 2 works fine but I want to know why the first one is wrong?
using (IDbCommand command = connection.CreateCommand())
{
command.CommandText = string.Format("SELECT COUNT(1) FROM {0}", tableName);
int count = (int)command.ExecuteScalar(); //statement 1
}
//int count = Convert.ToInt32(command.ExecuteScalar()); //statement 2
int
andInt32
are synonyms. – Toothy