|
Subject:
|
CInt versus Integer.Parse - what's the difference?
|
|
Posted By:
|
sektor
|
Post Date:
|
6/4/2008 1:10:21 AM
|
1) What's the difference between CInt and Integer.Parse? 2) Which of two is preferable?
|
|
Reply By:
|
planoie
|
Reply Date:
|
6/4/2008 8:53:07 AM
|
If I understand it correctly, CInt is only for conversion of compatible (and thus convertible) types.
You can convert a numeric type that is not an System.Integer32 (i.e. float, decimal, byte, single, etc.) into an System.Integer32 if the value is really an integer. If you tried to convert 1.1 to a System.Integer32 it would throw an exception.
You can not convert a System.String to a System.Integer32 even if the string's value is a numeric value (ex. "1"). You must parse the string. In the same vain, you basically can't convert a string to anything (perhaps aside from System.Object). It must be parsed (read) into the appropriate type (numeric, datetime, etc).
-Peter compiledthoughts.com
|
|
Reply By:
|
sektor
|
Reply Date:
|
6/5/2008 4:23:31 AM
|
Thanks a lot! So, when a user enters something in TextBox, then I gotta parse it instead of converting it to some data type. It's all clear now!
|