以下代码产生错误:
为什么会发生此错误?
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinApp_WMI2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CERas.CERAS = new CERas.CERAS();
}
}
}
最佳答案
改变
private void Form1_Load(object sender, EventArgs e)
{
CERas.CERAS = new CERas.CERAS();
}
到
private void Form1_Load(object sender, EventArgs e)
{
CERas.CERAS c = new CERas.CERAS();
}
或者,如果您希望以后再使用它
更改为
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinApp_WMI2
{
public partial class Form1 : Form
{
CERas.CERAS m_CERAS;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
m_CERAS = new CERas.CERAS();
}
}
}
关于c# - 如何解决 '…is a '类型“在给定上下文中无效”? (C#),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2278931/