use of unassigned local varible 'form2'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeonXie
    New Member
    • Nov 2010
    • 2

    use of unassigned local varible 'form2'

    Code:
    private void toolStripButton1_Click(object sender, EventArgs e)
            {
                Form2 form2;
                if (form2 == null || form2.IsDisposed)
                {
                    form2 = new Form2();
                    form2.MdiParent = this;
                    form2.Show();
                }
                else
                {
                    form2.Activate();
                }
            }
    Last edited by Curtis Rutland; Nov 9 '10, 02:34 PM.
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I think it's complaining because you're defining form2, then checking if it will equal null.

    In your case, form2 will never not be null. Either make form2 a class member or a parameter of some kind.

    Comment

    • LeonXie
      New Member
      • Nov 2010
      • 2

      #3
      Thanks!
      I'll try it.

      Comment

      Working...