-2

I have created two forms namely Form1 and Form2 their is a Button in form two when the Button is clicked Form2 should be displayed.But I keep getting the error "Form2 Type is not valid in the context"

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();
        Form2 in = new Form2();
        in.show();
    }
}

Image from application

Gilad Green
  • 36,708
  • 7
  • 61
  • 95

1 Answers1

1

in is a keywork of C# and you can't use it as a name for a variable. Change it or use @ in front of it:

MyClass @in = new MyClass();
@in.Something();

Read more here: What characters are allowed in C# class name?

Community
  • 1
  • 1
Gilad Green
  • 36,708
  • 7
  • 61
  • 95