Why not do the assignment in the if statement, so you don't have to cast it twice?