gpt4 book ai didi

c# - 如何解决 '...is a ' type', which is not valid in the given context'? (C#)

转载 作者:可可西里 更新时间:2023-11-01 03:14:26 26 4
gpt4 key购买 nike

以下代码会产生错误:

Error : 'CERas.CERAS' is a 'type', which is not valid in the given context

为什么会出现这个错误?

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 ' type', which is not valid in the given context'? (C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2278931/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com