r/programminghelp • • Dec 01 '23
C# Is this code possible in C#?
So I've been working with Actions and passing functions and I wanted to know if this is possible:Currently, this code will print 1, and I'd like the code to print 0. I've looked all over the internet for solutions and I can't find any.
void Action()
{
int i = 0;
Action action = () => Test(i);
i = 1;
action();
}
void Test(int i)
{
Console.WriteLine(i);
}
1
Upvotes
View all comments
Show parent comment
1
u/[deleted] Dec 01 '23
Yeah I know that, I need a way to change i to 1 without changing the variable stored in the action to 1 as well