static void Main(string[] args) { for (int i = 0; i < 3; i++) { for (int j = 2; j < 4; j++) { Debug.Print("----------"); Debug.Print(DebugMsg(() => i)); Debug.Print(DebugMsg(() => j)); } } } public static string DebugMsg<T>(Expression<Func<T>> expr) { var body = expr.Body as MemberExpression; var name = body.Member.Name; var value = ((FieldInfo)body.Member).GetValue(((ConstantExpression)body.Expression).Value); return name + " = " + value; }
---------- i = 0 j = 2 ---------- i = 0 j = 3 ---------- i = 1 j = 2 ---------- i = 1 j = 3 ---------- i = 2 j = 2 ---------- i = 2 j = 3
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.