Implicit Casting
suggest changeA 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);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents