Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between casting and conversion? [duplicate]

Eric Lippert's comments in this question have left me thoroughly confused. What is the difference between casting and conversion in C#?

like image 625
Joel Spolsky Avatar asked Jul 02 '10 14:07

Joel Spolsky


People also ask

What is the difference between conversion and casting?

In type casting, a data type is converted into another data type by a programmer using casting operator. Whereas in type conversion, a data type is converted into another data type by a compiler. 2. Type casting can be applied to compatible data types as well as incompatible data types.

What is the difference between casting and parsing?

Casting means taking a variable of one type and turning it to another type. There are obviously some combinations which can be cast, and some which cannot. Parsing means reading text and deciding what the different parts of it mean.

What is type conversion and casting in Java?

Converting one primitive datatype into another is known as type casting (type conversion) in Java. You can cast the primitive datatypes in two ways namely, Widening and, Narrowing. Widening − Converting a lower datatype to a higher datatype is known as widening.

What are the different types of conversion?

There are two types of conversion: implicit and explicit. The term for implicit type conversion is coercion. Explicit type conversion in some specific way is known as casting.


1 Answers

Casting is a way of telling the compiler "Object X is really Type Y, go ahead and treat it as such."

Conversion is saying "I know Object X isn't Type Y, but there exists a way of creating a new Object from X of Type Y, go ahead and do it."

like image 169
chrissr Avatar answered Sep 20 '22 06:09

chrissr