Evil Code 0001 : Lambda and Ref/out

What would be output of following ?

        static void Main(string [] args)
            List< int> numlist = new List< int>() {1,2, 3, 4, 5, 6, 7 };
            CalculateAndPrint( ref numlist);
        public static void CalculateAndPrint( ref List< int> Num)
            var n = Num.Where(d => d > Num[2]);
            foreach ( var item in n)

The most obvious answer is 4,5,6,7. However that’s not. This code refuses to compile because Lamba expressions  cannot accept variables that are declared in an outer scope.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s