So I understand what boxing and unboxing is. When\'s it come up in real-world code, or in what examples is it an issue? I can\'t imagine doing something like this example:>
Here is a really nasty one :)
SqlCommand cmd = ;
// This code works very well.
int result = (int)cmd.ExecuteScalar();
// This code will throw an exception.
uint result = (uint)cmd.ExecuteScalar();
The second execute fails because it tries to unbox an Int32 into an UInt32 which is not possible. So you have to unbox first and than cast.
uint result = (uint)(int)cmd.ExecuteScalar();