开发者

Compiler Error Message: Cannot implicitly convert type 'long' to 'string'

I have a issue in convertion. Whate 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(), strHFU开发者_运维百科pdate.ToString());
}

Appreciate your help!


 string srt = Convert.ToInt64(...);

Yes, that cannot work. Hard to guess what was intended here, maybe a missing parenthesis.


Here is the problem

string srt = Convert.ToInt64

You are trying to assign a long value to a string. 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, meaning 1.1 will throw an exception. An the string you are trying to convert is totally invalid, what was it supposed to do?


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 ]

ToInt64(String, IFormatProvider) Converts the specified string representation of a number to an equivalent 64-bit signed integer, using the specified culture-specific formatting information.

ToInt64(String, Int32) Converts the string representation of a number in a specified base to an equivalent 64-bit signed integer.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜