编译器错误消息:无法隐式转换类型“long”到“字符串”
我在转换方面遇到问题。这个转换有什么问题吗?
这是错误:
编译错误说明:在编译服务此请求所需的资源期间发生错误。请查看以下具体错误详细信息并适当修改您的源代码。
编译器错误消息:CS0029:无法将类型“long”隐式转换为“string”
if (hid_Action.Value.ToString().ToUpper() == "RENEW")
{
string strHFUpdate = string.Empty;
string srt = Convert.ToInt64(Session["AppId"] + ",'" + Session["CAAID"].ToString() + "','" + Session["UserType"].ToString() + "'");
strHFUpdate = "oea_sp_update_HF_MC_Renewal_Status " + srt;
rProxy.GlobalSaveData(Session["CountyName"].ToString().Trim(), strHFUpdate.ToString());
}
I have an issue in conversion. What is wrong with this conversion?
Here is the error:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0029: Cannot implicitly convert type 'long' to 'string'
if (hid_Action.Value.ToString().ToUpper() == "RENEW")
{
string strHFUpdate = string.Empty;
string srt = Convert.ToInt64(Session["AppId"] + ",'" + Session["CAAID"].ToString() + "','" + Session["UserType"].ToString() + "'");
strHFUpdate = "oea_sp_update_HF_MC_Renewal_Status " + srt;
rProxy.GlobalSaveData(Session["CountyName"].ToString().Trim(), strHFUpdate.ToString());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题如下:
您正在尝试将
long
值分配给string
。你不能。您必须使用.ToString()
将其更改为字符串,然后您才能分配。还有一个错误,
Convert.ToInt64
不会将数字转换为浮点数,这意味着1.1
将引发异常。您尝试转换的字符串完全无效,它应该做什么?Here is the problem
You are trying to assign a
long
value to astring
. You can't. You have to use.ToString()
to change it into a string, then you will be able to assign.And one more error,
Convert.ToInt64
doesn't convert number with float points, meaning1.1
will throw an exception. An the string you are trying to convert is totally invalid, what was it supposed to do?是的,那行不通。很难猜出这里的意图是什么,也许缺少括号。
Yes, that cannot work. Hard to guess what was intended here, maybe a missing parenthesis.
您无法将带有逗号和单引号的字符串转换为数字,此外,两个 ToInt64() 重载都采用第二个参数:
上面的代码试图将字符串隐式转换为 ToInt64() 可以采用的另一种数据类型对于具有单个参数的重载。 ToInt64() 确实支持从字符串转换,但这两个重载都采用两个参数(见下文)
[来自 MSDN:http://msdn.microsoft.com/en-us/library/system.convert.toint64.aspx ]
但正如我所提到的,即使您确实使用了正确的重载函数,由于非数字字符,您的字符串也将无法解析。
You can't convert a string with commas and single-quotes into a number, additionally, both ToInt64() overloads take a second parameter:
Your code above is trying to implicitly cast the string into another data-type that ToInt64() can take for an overload with a single parameter. ToInt64() does support converting from string but both those overloads take two parameters (see below)
[ From MSDN: http://msdn.microsoft.com/en-us/library/system.convert.toint64.aspx ]
But as I mentioned, even if you did use the correct overloaded function, your string would not be parse-able due to the non-numeric characters.