简体   繁体   English

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

[英]Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and 'string'

pls any one here can help me fix this请这里的任何人都可以帮我解决这个问题

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;
}

Error in line线路错误

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

Error :错误 :

Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and 'string'无法确定条件表达式的类型,因为“int”和“string”之间没有隐式转换

Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and 'string'无法确定条件表达式的类型,因为“int”和“string”之间没有隐式转换

This means that return type of !Versioned.IsNumeric(text2)) ? -1 : text2这意味着!Versioned.IsNumeric(text2)) ? -1 : text2返回类型!Versioned.IsNumeric(text2)) ? -1 : text2 !Versioned.IsNumeric(text2)) ? -1 : text2 can't be narrowed to single type. !Versioned.IsNumeric(text2)) ? -1 : text2不能缩小为单一类型。 It is either int ( -1 ) or string ( text2 ).它是 int ( -1 ) 或 string ( text2 )。

Treat both as string将两者都视为字符串

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

Now, in either case the result of the conditional tenary operator will be string现在,无论哪种情况,条件十元运算符的结果都将是字符串

Apply the condition outside在外部应用条件

int num = Versioned.IsNumeric(text2) ? Conversions.ToInteger(text2) : -1;
  • If text2 is numeric then convert string to int如果text2是数字,则将字符串转换为 int
  • If text2 is not numeric then use -1如果text2不是数字,则使用-1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法确定条件表达式的类型,因为在&#39;string&#39;和&#39;int&#39;之间没有隐式转换 - Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'int' 无法确定条件表达式的类型,因为&#39;int?&#39;之间没有隐式转换。 和“字符串” - Type of conditional expression cannot be determined because there is no implicit conversion between 'int?' and 'string' 无法确定条件表达式的类型,因为&#39;int&#39;和&#39;之间没有隐式转换 <null> “ - Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and '<null>' 无法确定条件表达式的类型,因为 &#39;int&#39; 和<null> - Type of conditional expression cannot be determined because there is no implicit conversion between 'int' and <null> 无法确定条件表达式的类型,因为“Entities.KRAParameterInfo”和“string”之间没有隐式转换 - Type of conditional expression cannot be determined because there is no implicit conversion between 'Entities.KRAParameterInfo' and 'string' 无法确定条件表达式的类型,因为&#39;string&#39;和&#39;System.DBNull&#39;之间没有隐式转换 - Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'System.DBNull' 嵌套三元隐式类型转换问题:由于在两个表达式之间没有隐式转换,因此无法确定条件表达式的类型 - Nested Ternary Implicit type Conversion issue: Type of conditional expression cannot be determined because there is no implicit conversion between C#ADO.Net无法确定条件表达式的类型,因为DBNull.Value与int之间没有隐式转换 - C# ADO.Net Type of conditional expression cannot be determined because there is no implicit conversion between DBNull.Value and int 无法确定条件表达式的类型,因为&#39;lambda expression&#39;和&#39;lambda expression&#39;之间没有隐式转换 - Type of conditional expression cannot be determined because there is no implicit conversion between 'lambda expression' and 'lambda expression' 无法确定条件表达式的类型,因为System.DateTime和null之间没有隐式转换 - Type of conditional expression cannot be determined because there is no implicit conversion between System.DateTime and null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM