开发者

performance difference between Int32.Parse or Int32.TryParse or System.Convert.ToInt32() [duplicate]

This question already has answers here: 开发者_开发百科 Closed 11 years ago.

Possible Duplicate:

Difference between Convert.ToInt32(string) and Int32.Parse?

are these three exactly the same in performance? or whats the deal?


  1. Parse v. TryParse
  2. Difference between Convert.ToInt32(string) and Int32.Parse?


Convert.ToInt32 works against object and accepts a range of data-types, of which `string is just one.

int.Parse is optimised for the very common string case, and raises an exception on failure. Useful when we expect an integer.

int.TryParse is like int.Parse, but no exception (false instead); useful for testing for an integer.


System.Convert check if the source object implements IConvertible and tehn call the proper method, so any object that "know" how to be converted to int can be converted that way. Parse and TryParse starts from the string reperesentation. Try parse returns a boolean signaling that conversion succeeded/failed. Parse trows if conversion fails.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜