There is no such thing as a C #

3

This is C # error, or I'm doing something wrong because in my logic this should work perfectly.

public partial class Form1 : Form
{

    Banco Bbanco;
    Bbanco = new Banco();

}
    
asked by anonymous 14.08.2017 / 05:41

1 answer

6

You can not make assignments in the body of a class separate from the declaration.

This does not work:

public class Test
{
    Banco BBanco;
    BBanco = new Banco();       
}

You can, however, do the assignment at the time of the declaration:

public class Test2
{
    Banco BBanco = new Banco();
}   

Or you can do the assignment within a method / constructor:

public class Test3
{
    Banco BBanco;

    public Test3()
    {
        BBanco = new Banco();
    }
}

You can check out here examples.

    
14.08.2017 / 12:04