Hello,
In the code below I pass method B as an action to be perfomed on on the objects in the IterateObjects method.
I would like to ask whether I can explicitly declare the method in the argument instead of passing it by name, something like this:
a.IterateObjects(delegate void(string s){//method body})
Its not correct but I am sure I have seen something like that working. Could you please advise? Thank you
DelTest a = new DelTest(); //class with method IterateObjects
a.IterateObjects(B) //HERE
private void B(string a)
{
listBox1.Items.Add(a);
}
//another class ....
public void IterateObjects(Action<string> akce)
{
foreach(string a in list)
{
akce(a);
}
}