2010-02-17 97 views
11

El código siguiente produce el error:¿Cómo resolver '... es un' tipo ', que no es válido en el contexto dado'? (C#)

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

¿Por qué ocurre este error?

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

Respuesta

16

Cambio

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

a

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

O si lo desea utilizarlo más adelante otra vez

cambio a

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


} 
3

CERAS es un nombre de clase que no se puede asignar. A medida que la clase implementa IDisposable un uso típico sería:

using (CERas.CERAS ceras = new CERas.CERAS()) 
{ 
    // call some method on ceras 
} 
4

Usted se olvidó de especificar el nombre de la variable. Debe ser CERas.CERAS newCeras = new CERas.CERAS();

Cuestiones relacionadas