Implicit Casting

suggest change

A value will automatically be cast to the appropriate type if the compiler knows that it can always be converted to that type.

int number = -1;
object value = number;
Console.WriteLine(value);

In this example, we didn’t need to use the typical explicit casting syntax because the compiler knows every int can be boxed to object. Console.WriteLine(-1) also compiles, but that call uses the WriteLine(int) overload, so it does not box. The assignment to object does.

Console.WriteLine(-1);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents