Type Casting
noun
say it: “TYPE KAST-ing” /taɪp ˈkæstɪŋ/
Telling C# to convert a value to another type by writing the type in parentheses, such as (int)4.7.
What is Type Casting in C#?
Type Casting — Explicitly converting a value to another compatible type.
class TicketCounter
{
void ConvertValues()
{
int tickets = 7;
double exactTickets = tickets;
int wholePrice = (int)7.9;
}
}
In a sentence
- “I used type casting, (int)average, to drop the decimals from the average score.”
Level: Novice · More C# terms at this level
Updated