请您参考如下方法:
这将编译正常。当然,您必须提供 thePort 真实设置。
namespace csWinFormsTest
{
public partial class Form1 : Form
{
static System.IO.Ports.SerialPort thePort;
public Form1()
{
InitializeComponent();
thePort = new System.IO.Ports.SerialPort("COM1");
}
static void fcn()
{
MessageBox.Show(thePort.PortName);
}
}
}
