modify a variable in a anonymous method

Posted by Navid Farhadi on Stack Overflow See other posts from Stack Overflow or by Navid Farhadi
Published on 2010-04-28T13:41:07Z Indexed on 2010/04/28 13:43 UTC
Read the original article Hit count: 335

I want to modify a local variable in a function of extension method. See

int myvar=0;
MyList.Where(
    x =>
        {
            if (condition)
                myvar += 1;
            return false;
        });
return myvar;

But that is not working. What is the problem.

© Stack Overflow or respective owner

Related posts about c#

Related posts about anonymous-methods