public static void ForeachWithCapturedVariable(List <int> items) { foreach (int item in items) { int c = item; Loops.Operation(() => c == 5); } }
public static void ForeachWithRefUsage(List <int> items) { foreach (int item in items) { int current = item; Loops.Operation(ref current); } }
public static void ForeachWithRefUsage(List <int> items) { foreach (int item in items) { #if ROSLYN && OPT // The variable name differs based on whether roslyn optimizes out the 'item' variable int current = item; Loops.Operation(ref current); #else int num = item; Loops.Operation(ref num); #endif } }