You will often need to convert between different types. For example, data input is often done into a text field, so it is initially stored in a variable of the string
type, but it then needs to be converted into a date, or time, or number, or some other data type, depending on how it should be stored and processed.
Casting has two varieties: implicit and explicit. Implicit casting happens automatically and it is safe, meaning that you will not lose any information. Explicit casting must be performed manually because it may lose information, for example, the accuracy of a number. By explicitly casting, you are telling the C# compiler that you understand and accept the risk.
Add a new console application project named CastingConverting
.