如题,想知道这行代码的含义 foreach (System.Windows.Forms.Form fm in System.Windows.Forms.Application.OpenForms)
遍历所有打开的窗体
foreach
是遍历in
后面的集合的每一个元素。
题中的foreach
是遍历集合System.Windows.Forms.Application.OpenForms
中的每一个元素,其中:元素的类型为System.Windows.Forms.Form
,fm
是变量名,你可以在foreach
的语句块中使用变量fm
来完成业务逻辑。
for each 则是遍历集合中的每一个元素(即窗体) : https://docs.microsoft.com/zh-cn/dotnet/visual-basic/language-reference/statements/for-each-next-statement