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/aizzod Dec 01 '23
that does not make sense.
either you use your variable i.
or you don't.
or you create a new one.
i think you have a simple problem, but try to solve it as complicated as possible right now. with a proper use case it would be asier to explaine