Bun
Bun

Reputation: 73

Declaring Datatype as Form

I want to declare a parameter as Form at the below:

void Func(Form frm)
{
    frm emp = new frm();
}

but I got an error I can't delcare like that. Any suggestion ?

Upvotes: 0

Views: 42

Answers (2)

Vadim Martynov
Vadim Martynov

Reputation: 8902

You are using variable (method parameter) that is the instance of object as a type name.

You should not call new operator because you are already have created instance.

New operator used to create objects and invoke constructors.

Then you just need to use the assignment operator or use variable as is:

void Func(Form frm)
{
    frm.Show();
    //Form emp = frm;
}

Upvotes: 2

fubo
fubo

Reputation: 46005

frm is a variable not a type

void Func(Form frm)
{
    Form emp = frm;
}

Upvotes: 7

Related Questions