Type Casting in C#
What is the difference between Implicit and Explicit Type Casting? How does Explicit Type Casting take place in c sharp?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Krishna GaradRank #191 · 12.8K reputationPosted Mar 24, 2011, 8:27 PM EDT
Soft CornerRank #1,221 · 1.5K reputationPosted Mar 24, 2011, 8:32 PM EDT
First of all this should be clear:
1.For both implicit and explicit typing, the type of the variable is known at compile time, even if it's not explicitly stated .
2.The difference between implicit and explicit typing is only pertinent if we are discussing about statically typed language like c#.
With explicit typing, the type of every variable must be explicitly stated in the declaration. Implicit typing allows the compiler to infer the type of the variable based on its use. What that means in the case of implicit typing is Type inference comes into play , a good definition regarding type inference is at Wikipedia:
Type Inference
Type inference, or implicit typing, refers to the ability to deduce automatically the type of a value in a programming language. It is a feature present in some strongly statically typed languages.
Implicit type you can also think of "var" type that is introduced in c# frmwrk 3 . "var" figures out what type it is by the value supplied on the right-hand side of the assignment. Remember using "var" we are not breaking the c# strongly typed feature, we are still working on strongly typed.