hi
how to resolve this error
c# Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
hi
how to resolve this error
c# Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?)
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
Eamonn22 reputationPosted Jul 27, 2009, 12:04 PM EDT
This cannot be done without an explicit cast, and is very risky as it can result in unpredictable results.
To do an explicit cast you can do this.
However, if longVariable exceeds the maximum allowed value for an Int32, this will not thrown an overflow exception, but will set integerVariable to -1.
Another way of doing it is to use the System.Convert class which will throw an OverFlowException.