如何将char转换为int? [英] How to convert char to int?

查看:989
本文介绍了如何将char转换为int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是正确的方式转换成一个字符 INT ? 这给 49

What is the proper way to convert a char to int? This gives 49:

int val = Convert.ToInt32('1');
//int val = Int32.Parse("1"); // Works

我不想转换为字符串,然后分析它。

I don't want to convert to string and then parse it.

推荐答案

我很惊讶没有人提到的内置到 System.Char ... <静态方法/ P>

I'm surprised nobody has mentioned the static method built right into System.Char...

int val = (int)Char.GetNumericValue('8');
// val == 8

这篇关于如何将char转换为int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆