PC Review


Reply
Thread Tools Rate Thread

about convert from string to int

 
 
tony
Guest
Posts: n/a
 
      16th Jun 2006
Hello!!


string number = "13";
int num;
Is it exactly the same if I use
num = Convert.ToInt32(number); OR
num = int.Parse(number)

Is it always in this case that I can choose whichever of int.Parse or
Convert.ToInt32 when I convert from a string containing numbers to an int.
So are these two interchangeable.

//Tony


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljaGFlbCBOZW10c2V2?=
Guest
Posts: n/a
 
      16th Jun 2006
Convert.ToInt32 returns zero if string is null reference, when int.Parse
throws ArgumentNullException

> string number = "13";
> int num;
> Is it exactly the same if I use
> num = Convert.ToInt32(number); OR
> num = int.Parse(number)
>
> Is it always in this case that I can choose whichever of int.Parse or
> Convert.ToInt32 when I convert from a string containing numbers to an int.
> So are these two interchangeable.


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      16th Jun 2006
Hi,

> Is it always in this case that I can choose whichever of int.Parse or
> Convert.ToInt32 when I convert from a string containing numbers to an int.
> So are these two interchangeable.


Mostly, the difference is when the string is not a number as the other
posted said.

IIRC one of then use the other internally, This has been discussed here
several time, search in the archives to have more details , even a benchmark
of both.


--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


 
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 'System.Collections.ObjectModel.ReadOnlyCollection(Of String)' to '1-dimensional array of String'. roidy Microsoft VB .NET 12 17th Jul 2009 10:53 AM
Convert Dictionary<string,SomeType> keys to List<string> buzzweetman@gmail.com Microsoft C# .NET 6 9th Aug 2006 03:54 PM
convert html-string to plain text-string Nedo Microsoft Dot NET 4 28th Jul 2005 09:53 AM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= Microsoft ASP .NET 2 26th Oct 2004 03:43 PM
Convert a string to Ascii codes and then back to string again Kai Bohli Microsoft C# .NET 11 8th Jul 2004 03:22 PM


Features
 

Advertising
 

Newsgroups
 


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