Requesting examples for how to properly do this: (The reasons for doing it like this are plenty, and in this case there is no better way)
public void customForLoop(CodeThatCaBeExecuted _code1, CodeThatCaBeExecuted _code2)
{
for(int i = 0; i < number1; i++)
{
_code1 //Doing something with i
for(int j = 0; j < number2; j++)
{
_code2 //Doing something with j
}
}
}
The situation:
I have a list of Player
objects. The first for loop
loops trough all the players in the list. The 2nd for loop
runs trough a list of information about the selected player. I have to do this several times trough the code, so I would like to be able to fill in the repeating code in the function and call the method with the required additional code.
In this case _code1 is for example: if(something) do something;
In short: I want to execute an argument.
More complex explaination by request: I want to make a function that contains code i need in every case. I also want t be able to fill in more code in the form of arguments, because most of the situations in wich i need this method it is slightly diferent (1 or 2 lines). The hole function itself is rather large and complex, and therefore i would like to be able to fill in the minor changes that i need.
I must stress this: I do not want to pass a function as an argument. I want to be able to insert code directly.