PC Review


Reply
Thread Tools Rate Thread

Convert.ToInt32(char)

 
 
omeraa@gmail.com
Guest
Posts: n/a
 
      17th Jan 2006
If we pass in '9' the above function should return 9, but it doesnt. It
returns 57, which is the unicode representation of the character 9.

However if we use Convert.Int32(string), and pass in "9", it returns 9.

Any ideas why?

 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      17th Jan 2006
<(E-Mail Removed)> wrote:
> If we pass in '9' the above function should return 9, but it doesnt. It
> returns 57, which is the unicode representation of the character 9.


What makes you think it should return 9?

> However if we use Convert.Int32(string), and pass in "9", it returns 9.
>
> Any ideas why?


Because they both act as documented. From Convert.ToInt32(char):

<quote>
Converts the value of the specified Unicode character to the equivalent
32-bit signed integer.
</quote>

From Convert.ToInt32(string):
<quote>
Converts the specified String representation of a number to an
equivalent 32-bit signed integer.
</quote>

Note the difference between the string (i.e. textual) *representation*
of a number and an actual *value*. (Any char is in itself a 16 bit
unsigned value.)

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert::ToInt32 problem Dave Farquharson Microsoft Dot NET Framework 3 9th May 2008 11:02 PM
IsNumeric: Convert.ToInt32 vs. Convert.ToInt64 sck10 Microsoft ASP .NET 4 3rd Sep 2006 10:40 PM
Difference between Cint and Convert.ToInt32 ? =?Utf-8?B?UmljaA==?= Microsoft VB .NET 4 22nd Jul 2006 05:50 AM
(int) or convert.ToInt32 ? =?Utf-8?B?SmFyb2Q=?= Microsoft C# .NET 8 22nd Jun 2005 07:07 PM
Advantage between (int) and Convert.ToInt32? =?Utf-8?B?Y2hhcmxpZXdlc3Q=?= Microsoft C# .NET 1 16th Feb 2005 06:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 AM.