If in doubt: cast, cast and cast again
-
My colleague found this and other horrors in a newish project. Bearing in mind that "Id" is a nullable int and result.ID is a regular int, who in their right mind would do this (object and function names have been changed to protect the incompetent):
protected Thing populateThing(DataRow dr)
{
Thing result = new Thing();
result.Id = int.Parse(dr["Id"].ToString());BTW, note no handling of the case when "Id" is DBNULL. You can stop laughing now.
-
My colleague found this and other horrors in a newish project. Bearing in mind that "Id" is a nullable int and result.ID is a regular int, who in their right mind would do this (object and function names have been changed to protect the incompetent):
protected Thing populateThing(DataRow dr)
{
Thing result = new Thing();
result.Id = int.Parse(dr["Id"].ToString());BTW, note no handling of the case when "Id" is DBNULL. You can stop laughing now.
And with what did you replace it?
-
And with what did you replace it?
-
My colleague found this and other horrors in a newish project. Bearing in mind that "Id" is a nullable int and result.ID is a regular int, who in their right mind would do this (object and function names have been changed to protect the incompetent):
protected Thing populateThing(DataRow dr)
{
Thing result = new Thing();
result.Id = int.Parse(dr["Id"].ToString());BTW, note no handling of the case when "Id" is DBNULL. You can stop laughing now.