Type Casting is an actively used design pattern.

?Years Old
  • Type Casting ranks in the top 50% of entities I track
  • the Type Casting wikipedia page
  • I have 10 facts about Type Casting. what would you like to know? email me and let me know how I can help.

Languages with Type Casting include c, csharp, typescript

Example from c:

double da = 3.3;
double db = 3.3;
double dc = 3.4;
int result = (int)da + (int)db + (int)dc; //result == 9

Example from csharp:

Animal animal = new Cat();

Bulldog b = (Bulldog) animal;   // if (animal is Bulldog), stat.type(animal) is Bulldog, else an exception
b = animal as Bulldog;          // if (animal is Bulldog), b = (Bulldog) animal, else b = null

animal = null;
b = animal as Bulldog;          // b == null

Example from typescript:


Last updated November 6th, 2019