Close all open forms except the main menu in C#

前端 未结 8 1833
终归单人心
终归单人心 2020-12-16 14:27

Trying to close all forms except for the main menu using

FormCollection formsList = Application.OpenForms;

with a foreach loop and saying,

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 15:20

    As the error states, you can't modify a collection in its foreach.

    Instead, you can use a backwards for loop.

提交回复
热议问题