C# Language Casting Implicit Casting

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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 all ints can be cast to objects. In fact, we could avoid creating variables and pass -1 directly as the argument of Console.WriteLine() that expects an object.

Console.WriteLine(-1);


Got any C# Language Question?