Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trouble with casting
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01608054
Message ID:
01608074
Views:
21
>>It doesn't work because the compiler knows that when you add 2 shorts together you could overflow (so it needs an int/Int32 to store the result). It wants you to specifically cast the result of the addition to a (short) before it gets assigned to newSuffix so it knows that you understand the consequences that you could possibly lose data. If you want it as one line:
>>
>>
>>newSuffix = Convert.ToInt16(lastLocSuffix) + 1;
>>
>
>Thanks, Paul. I think I tried that version already and got the same problem. Two lines assignment works.

Doh! Yeah, I messed that up when I tested it. I set newSuffix as an int, not a short. BTW - you never actually said what type lastLocSuffix was.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform