views:

753

answers:

3

i want to call this class from my Winform.But if i write this codes. Compiler send me error. What is solution. Please help me


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();
        }
    }
}
+4  A: 

Change

private void Form1_Load(object sender, EventArgs e) 
    { 
        CERas.CERAS = new CERas.CERAS(); 
    } 

to

private void Form1_Load(object sender, EventArgs e) 
    { 
        CERas.CERAS c = new CERas.CERAS(); 
    } 

Or if you wish to use it later again

change it to

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(); 
    } 
} 


}
astander
+2  A: 

CERAS is a class name which cannot be assigned. As the class implements IDisposable a typical usage would be:

using (CERas.CERAS ceras = new CERas.CERAS())
{
    // call some method on ceras
}
Darin Dimitrov
+1  A: 

You forgot to specify the variable name. It should be CERas.CERAS newCeras = new CERas.CERAS();

Marcel Gheorghita