C#为什么这回49:Convert.ToInt32(“1”) [英] c# why does this return 49: Convert.ToInt32('1')

查看:113
本文介绍了C#为什么这回49:Convert.ToInt32(“1”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
C#字符转换成int

本作品:

int val = Convert.ToInt32("1");



但是,这并不:

But this doesn't:

int val = Convert.ToInt32('1'); // returns 49



不应该将其转换为实际的诠释?

Shouldn't this convert to actual int?

推荐答案

它返回字符1

第一条语句把参数作为字符串转换价值转换成int,
中的第二个把参数为char并返回其ASCII值

The first statement treats the argument as string and converts the value into Int, The second one treats the argument as char and returns its ascii value

这篇关于C#为什么这回49:Convert.ToInt32(“1”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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