Generic collection of MenuItems in C#? -


i working on displaying list of audio input devices in menu, , i'm new c#. number of input devices not varies machine machine, possible might add or subtract usb device while program running. wrote code checks whenever menu activated, have limit number of possible input devices. it's not there more 10 input devices, but, in order understand c# better, i'd see if it's possible use generic don't have limit list.

here's have going code now:

mainmenu sgfilemenu = new mainmenu();  list<menuitem> inputdevice = new list<menuitem>();  menuitem mymenuiteminput = new menuitem("&input devices"); sgfilemenu.menuitems.add(mymenuiteminput);  (int = 0; < devicecount; i++) {     mymenuiteminput.menuitems.add(inputdevice[i]); } 

that compiles gives argumentoutofrange exception when run it. i'm missing how generics set up- can clue me in?

added after reading of comments- devicecount integer , not 0- that's checked someplace else. seems clear need before:

    mymenuiteminput.menuitems.add(inputdevice[i]); 

but i'm not sure is.

try this:

for (int = 0; < inputdevice.count; i++) {     mymenuiteminput.menuitems.add(inputdevice[i]); } 

anyway, you've initialized inputdevice empty list, doesn't contain menuitem.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -