无法将类型string隐式转换为int怎么解决?
答案:6 悬赏:50 手机版
解决时间 2021-04-14 11:24
- 提问者网友:爱了却不能说
- 2021-04-14 06:04
无法将类型string隐式转换为int怎么解决?
最佳答案
- 五星知识达人网友:未来江山和你
- 2021-04-14 07:42
你的ClassroomBuilding和 ClassroomStep这两个变量类型都是int类型的,而 buildnum和 floor是string类型的,所以不能这样直接赋值。把这两句改成:
classroom.ClassroomBuilding = int.Parse(buildnum);
classroom.ClassroomStep = int.Parse(floor);
或者将ClassroomBuilding和 ClassroomStep这两个变量类型改成string
classroom.ClassroomBuilding = int.Parse(buildnum);
classroom.ClassroomStep = int.Parse(floor);
或者将ClassroomBuilding和 ClassroomStep这两个变量类型改成string
全部回答
- 1楼网友:忘川信使
- 2021-04-14 11:33
显示转换
classroom.ClassroomStep = (int)floor;追问这样试了一下,还是不可以
classroom.ClassroomStep = (int)floor;追问这样试了一下,还是不可以
- 2楼网友:杯酒困英雄
- 2021-04-14 11:25
三种方法:
1、classroom.ClassroomBuilding = (int)buildnum;
2、classroom.ClassroomBuilding = Int.Paras(buildnum);
3、classroom.ClassroomBuilding = Convert.ToInt32(buildnum);追问我用了以下第三种方法,能够执行,但显示错误说输入字符串的格式不正确,该怎么办追答要输入纯数字,如果有字母或符号就会报错
1、classroom.ClassroomBuilding = (int)buildnum;
2、classroom.ClassroomBuilding = Int.Paras(buildnum);
3、classroom.ClassroomBuilding = Convert.ToInt32(buildnum);追问我用了以下第三种方法,能够执行,但显示错误说输入字符串的格式不正确,该怎么办追答要输入纯数字,如果有字母或符号就会报错
- 3楼网友:往事埋风中
- 2021-04-14 10:25
把classroom.ClassroomBuilding = buildnum
改成classroom.ClassroomBuilding =Convert.ToInt32(buildnum )
改成classroom.ClassroomBuilding =Convert.ToInt32(buildnum )
- 4楼网友:污到你湿
- 2021-04-14 09:08
写成这样试试string buildnum = building.Text.Trim();
classroom.ClassroomBuilding = Convent.ToInt32(buildnum);
string floor = flor.Text.Trim();
classroom.ClassroomStep = Convent.ToInt32(floor);
classroom.ClassroomBuilding = Convent.ToInt32(buildnum);
string floor = flor.Text.Trim();
classroom.ClassroomStep = Convent.ToInt32(floor);
- 5楼网友:佘樂
- 2021-04-14 08:34
classroom.ClassroomStep = int.Parse(floor);
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯