无法确定条件表达式的类型,因为"int"和"string"之间没有隐式转换



这里有谁可以帮我解决这个问题

checked
{
foreach (string text2 in ParametersString)
{
int num = Conversions.ToInteger((!Versioned.IsNumeric(text2)) ? -1 : text2);
if (num == -1)
{
Interaction.MsgBox(string.Format("Entering characters is not allowed ---> {0}", text2), MsgBoxStyle.Critical, Class10.string_4);
}
else if (!this.method_2(num))
{
Interaction.MsgBox(string.Format("The specified port ({0}) is already in use", text2), MsgBoxStyle.Critical, Class10.string_4);
Environment.Exit(0);
}
else
{
this.Listener = new TcpListener(IPAddress.Any, num);
this.Listener.Server.SendTimeout = -1;
this.Listener.Server.ReceiveTimeout = -1;
this.Listener.Server.SendBufferSize = 999999;
this.Listener.Server.ReceiveBufferSize = 999999;
this.Listener.Start();
int num2 = 5;
string string_ = Class7.string_0;
if (Operators.CompareString(string_, "High", false) != 0)
{
if (Operators.CompareString(string_, "Normal", false) == 0)
{
num2 = 10;
}
else if (Operators.CompareString(string_, "Low", false) == 0)
{
num2 = 5;
}
}
else
{
num2 = 16;
}
int num3 = num2;
for (int j = 1; j <= num3; j++)
{
new Thread(new ThreadStart(this.ScanerAsync)).Start();
}
int num4 = num2;
for (int k = 1; k <= num4; k++)
{
new Thread(new ThreadStart(this.method_1)).Start();
}
text += Conversions.ToString(num);
this.closing = false;
}
}
Class6.string_0 = text;
}

行错误
int num = Conversions.ToInteger((!Versioned.IsNumeric(text2)) ? -1 : text2);

错误:

不能确定条件表达式的类型,因为在'int'和'string'之间没有隐式转换

不能确定条件表达式的类型,因为'int'和'string'之间没有隐式转换

这意味着不能将!Versioned.IsNumeric(text2)) ? -1 : text2的返回类型缩小为单一类型。它可以是int (-1)或string (text2)。

将两者视为字符串

int num = Conversions.ToInteger((!Versioned.IsNumeric(text2)) ? "-1" : text2);

现在,在任何情况下,条件实参操作符的结果都将是string

应用外部条件

int num = Versioned.IsNumeric(text2) ? Conversions.ToInteger(text2) : -1;
  • 如果text2是数字,则将字符串转换为int
  • 如果text2不是数字,则使用-1

相关内容

  • 没有找到相关文章

最新更新