So I have some an int x I need to pass to another function, the problem is x changes before I use the function, so the value x changes to a different value than I want it. Is there a way to duplicate an integer (I couldn't find one)? That would solve my problem.
private void Init()
{
for (int x = 0; x < 10; x++)
{
for (int y = 0; y < 10; y++)
{
Button tmpButton = new Button();
tmpButton.Click += (sender, e) => ButtonClick(sender, e, x, y);
//x and y need to "freeze" their value at this point
}
}
}
private void ButtonClick(object sender, EventArgs e, int x, int y)
{
Console.Out.WriteLine(x.ToString() + ":" y.ToString());
}
Output: "10:10"
Expected Output (if clicked on button 3,4): "3:4"