A local variable named 'port' cannot be declared

This question already has an answer here:

  • C# variable scoping: 'x' cannot be declared in this scope because it would give a different meaning to 'x' 3 answers

  • You have a variable named port in your code already. So it doesn't allow you to declare it again in your foreach loop. Change it's name to something else:

    foreach (string port2 in ports)
    {
        comboBox1.Items.Add(port2);
    }
    
    链接地址: http://www.djcxy.com/p/53056.html

    上一篇: foreach()错误警告:为foreach()提供的无效参数

    下一篇: 名为'port'的局部变量不能声明