如何解决无法将类型'int'隐式转换为'string'错误 [英] How to solve Cannot implicitly convert type 'int' to 'string' error

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

问题描述

大家好



我在c#中的一个项目工作,我遇到了错误

无法隐式转换类型 int'到'string'



以下是我的代码:

Hi Everyone

I am working on a project in c# where I am stuck at an error
"Cannot implicitly convert type 'int' to 'string'"

Following is my code:

int att = 0;
att = command.Parameters["@recNo"].Value;
rtn = att;



我甚至尝试了以下代码但没有帮助


I even tried the below code but didn't help

att = Convert.ToInt32(command.Parameters["@recNo"].Value);



请帮助



谢谢


Please Help

Thank You

推荐答案

错误说您正在尝试将int转换为字符串,而不是将字符串转换为int。



这告诉我rtn必须是一个字符串,你试图将att加入其中。该错误应该显示您导致它的哪一行。但是,只需要



The error says you are trying to convert an int to string, not a string to int.

This tells me that rtn must be a string and you're trying to put att into it. The error should have shown you which line caused it. However, just do

rtn = att.ToString();

这篇关于如何解决无法将类型'int'隐式转换为'string'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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