Pregunta

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.

¿Fue útil?

Solución

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

Otros consejos

"Culture-specific information" refers to the ways numbers can be written in different cultures. For example, in the US, you might write 1 million as:

1,000,000

But other cultures use the comma as a decimal separator, so you might see

1'000'000

or:

1 000 000

or, of course (in any culture):

1000000
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top