问题描述
大家好,
C#中的新手,出现了给定的错误,
无法将类型"object"隐式转换为"int".存在显式转换(您是否缺少演员表?)
源错误:
第262行:int verifycount_result = 0;
第263行:
第264行:verifycount_result = Destinations_Alloc_Count();
265行:
第266行:if(verifycount_result =="1")
我的代码是:
hi all,
am new in c#, i got the given error,
Cannot implicitly convert type ''object'' to ''int''. An explicit conversion exists (are you missing a cast?)
Source Error:
Line 262: int verifycount_result=0;
Line 263:
Line 264: verifycount_result = Destinations_Alloc_Count();
Line 265:
Line 266: if(verifycount_result=="1")
my code is:
int verifycount_result=0;
verifycount_result = Destinations_Alloc_Count();
if(verifycount_result=="1")
{
public object Destinations_Alloc_Count()
{
string result = null;
result = "";
try
{
SqlConnection con = new SqlConnection(sqlconn_cmsstr);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("select count(divertedto) from Hotdial where accountnumber='" + Session["user_id"] + "'", con);
int i = 0;
i = 0;
i = int.Parse(cmd.ExecuteScalar());
if (i > 200)
{
result = "0";
return result;
}
else
{
result = "1";
return result;
}
}
catch (Exception ex)
{
result = "-1";
return result;
}
}
推荐答案
public string Destinations_Alloc_Count()
2)将变量更改为字符串类型
2) Change your variable to be a string type
string verifycount_result = string.Empty;
verifycount_result = Destinations_Alloc_Count();
尝试保持相同的类型,否则您将遇到类似这样的问题
Try and keep your types the same, or you will have issues like this
这篇关于无法将类型'object'隐式转换为'int'.存在显式转换(您是否缺少演员表?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!