Search code examples
c#.netparsingint32

How does Int32.Parse() exactly parse the String?


I am a novice C# learner. I know the basic concepts of this language. While revising the concepts, I stumbled upon one problem - How does Int32.Parse() exactly work?

Now I know what it does and the output and the overloads. What I need is the exact way in which this parsing is accomplished.

I searched on the MSDN site. It gives a very generalized definition of this method (Converts the string representation of a number to its 32-bit signed integer equivalent.) So my question is - How does it convert the string into a 32-bit signed integer?

On reading more, I found out 2 things -

  1. The string parameter is interpreted using the "NumberStyles" enumeration
  2. The string parameter is formatted and parsed using the "NumberFormatInfo" class

I need the theory behind this concept. Also, I did not understand the term - "culture-specific information" from the definition of the NumberFormatInfo class.


Solution

  • Here is the relevant code, which you can view under the terms of the MS-RSL.