Search code examples
c#winformsidisposableusing

IDisposable Control added to Form inside using statement?


In the code example below, does the RadioButton rb still exist in Form mainForm after the code leaves the using statement and rb is disposed?

using (var rb = new RadioButton())
{
    rb.Text = "Test Radio Button";
    rb.Checked = true;

    mainForm.MyPanel.Controls.Add(rb);   
}

Solution

  • It still exists as an object, but it may be trash, as you have Disposed it, once execution leaves that using block.