Is there a way to configure the VS2008 C# compiler to give a warning for code like this:
Int64 x = 123456789000;
Int32 y = (Int32)x;
SAFE FOR HUMANS AND DOGS - Can-C is the first and only patented NAC eye drop that uses the exact formula proven effective in both animal and human trials, offering a non-invasive alternative to cataract surgery. EVERY BLINK HYDRATES and lubricates the eye and cornea.
Can-C's ingredients help to soothe and rejuvenate tired eyes, help with macular degeneration, cataracts, and other age-related eye disorders. Can-C eye drops for cataracts contain lubricants, an antioxidant and an anti-glycating agent, N-Acetyl-Carnosine (NAC).
Do not use this medication for longer than 3 to 4 days at a time.
Can-C is packaged as an eye lubricant because it is not approved by the FDA as a drug to treat cataracts. Besides an eye lubricant it may also be helpful for eye strain, ocular inflammation, blurred vision, dry eye, corneal disorders and retinal diseases.
The whole point of an explicit cast is to say that "I take responsibility for the problem, please just do it."
In your trivial case, it would perhaps be easy for the compiler to figure out that the value would not fit in a Int32, and thus produce your warning.
However, what about this:
Int64 x = CallSomeMethod();
Int32 y = (Int32)x;
How can it warn you about this? Should it:
The best you can hope for here is to have a runtime check, or similar, the compiler cannot prevent you from everything that could go wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With