<p>I have a char in c#:</p>

<pre><code>char foo = '2';
</code></pre>

<p>Now I want to get the 2 into an int.  I find that Convert.ToInt32 returns the actual decimal value of the char and not the number 2.  The following will work:</p>

<pre><code>int bar = Convert.ToInt32(new string(foo, 1));
</code></pre>

<p>int.parse only works on strings as well.  </p>

<p>Is there no native function in C# to go from a char to int without making it a string?  I know this is trivial but it just seems odd that there's nothing native to directly make the conversion.</p>

This will convert it to an
```
int
```
:
```
```
char foo = '2';
int bar = foo - '0';
```
```
This works because each character is internally represented by a number. The characters
```
'0'
```
to
```
'9'
```
are represented by consecutive numbers, so finding the difference between the characters
```
'0'
```
and
```
'2'
```
results in the number 2.