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
0
u/[deleted] Dec 01 '23
Its fine, I found a simple fix for my problem, but thanks for helping