-
Can someone help me annotate this code, I don't fully understand it
over 8 years ago
-
over 8 years ago
Hi beccahalford,
As far as the functionality of this code is concerned, it is a code snippet from some kind of online test engine. The code written is for resetting the answer radio buttons to blank if the test taker wants to.
public IEnumerable
GetAll(Control control, Type type) { var controls = control.Controls.Cast (); return controls.SelectMany(ctrls => GetAll(ctrls, type)).Concat(controls).Where(c => c.GetType() == type); } Above is the method which gets the control type, in this particular case-The radio buttons.
Now comes the click method which is bound to execute on a "Reset" button click.progressBar1.Increment(-100);//For progress bar running student_name_txtbox.Clear();//Some student name is cleared from textbox.Again I dont know the reference. var cntls = GetAll(this, typeof(RadioButton)); //Above described GetAll Method used to get all radio buttons by type. Consider the "typeof" syntax. foreach (Control cntrl in cntls) { RadioButton rbtn = (RadioButton)cntrl; if (rbtn.Checked) { rbtn.Checked = false; } }
Above is the foeach loop for clearing the checks of radio buttons, and that's all.
-
1 Answer(s)