i have code. the constructor should enter the GetItems
function but when i place breakpoint, it simply do not stop.
what is the problem?
namespace Storehouse {
public partial class MainForm : Form {
public MainForm() {
InitializeComponent();
var a = GetItems(fILEToolStripMenuItem);
}
public IEnumerable<ToolStripMenuItem> GetItems(ToolStripMenuItem item) {
foreach (ToolStripMenuItem dropDownItem in item.DropDownItems) {
if (dropDownItem.HasDropDownItems) {
foreach (ToolStripMenuItem subItem in GetItems(dropDownItem)) {
yield return subItem;
}
yield return dropDownItem;
}
}
}
}
When you're using yield, it means deferred execution, so you need to enumerate your variable a
, like this:
var a = GetItems(fILEToolStripMenuItem).ToList();
You can also use ToArray()
, whatever, you simply need to enumerate your IEnumerable
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With