Thursday, June 19, 2014

[ Stack Overflow ] What is the difference between explicit and implicit type casts?

Explicit cast:

int x =0;float y =3.8f;

x +=(int) y;//Explicit cast.

This tells the compiler that the cast was intentional and that you know that the fractional part will go lost. The compiler won't complain.

Implicit cast:

int x =0;float y =3.8f;

x += y;//Implicit cast

The compiler will complain because the fractional part will be lost when converting float to int.

c# - What is the difference between explicit and implicit type casts? - Stack Overflow

Explicit cast:

int x =0;float y =3.8f;

x +=(int) y;//Explicit cast.

This tells the compiler that the cast was intentional and that you know that the fractional part will go lost. The compiler won't complain.

Implicit cast:

int x =0;float y =3.8f;

x += y;//Implicit cast

The compiler will complain because the fractional part will be lost when converting float to int.

No comments:

Know us

Our Team

Tags

Video of the Day

Contact us

Name

Email *

Message *