Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

constructor do not enter a function C#

Tags:

function

c#

call

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;
                }

            }

        }
}
like image 597
M.G. Avatar asked Nov 19 '16 13:11

M.G.


1 Answers

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.

like image 123
Yurii N. Avatar answered Sep 21 '22 23:09

Yurii N.