Type Casting in C#
What is the difference between Implicit and Explicit Type Casting? How does Explicit Type Casting take place in c sharp?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Soft CornerPosted Mar 25, 2011, 12:32 AM
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.
Krishna GaradPosted Mar 25, 2011, 12:27 AM