如何解决无法将类型'int'隐式转换为'string'错误

如何解决无法将类型'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();

>