A local variable named 'port' cannot be declared
本问题已经有最佳答案,请猛点这里访问。
我正在尝试构建一个Arduino项目,通过开放硬件监视器来测量CPU和GPU温度,现在我在C应用程序中遇到了问题。
它在第45行给出了这个错误:
A local variable named 'port' cannot be declared in this scope
because it would give a different meaning to 'port', which is already
used in a 'parent or current' scope to denote something else
我能得到帮助吗?非常感谢你!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | private void Init() { try { notifyIcon1.Visible = false; port.Parity = Parity.None; port.StopBits = StopBits.One; port.DataBits = 8; port.Handshake = Handshake.None; port.RtsEnable = true; string[] ports = SerialPort.GetPortNames(); 45 foreach (string port in ports) { comboBox1.Items.Add(port); } port.BaudRate = 9600; } catch (Exception ex) { MessageBox.Show(ex.Message); } } |
代码中已经有一个名为
1 2 3 4 | foreach (string port2 in ports) { comboBox1.Items.Add(port2); } |