🌈 搜索
📅  最后修改于: 2022-03-11 14:49:03.985000             🧑  作者: Mango
List asd = new List(); for (int i = 0; i < asd.Count; i++) { // Let's say you are trying to create buttons // Because the memory address gets overwritten // the button will always use the last value looped Button btn = new Button() { Click += SomeMethod(asd[i]) }; // This is crucial as this will reference // a new memory address. object obj = asd[i]; // So do it like this Button btn = new Button() { Click += SomeMethod(obj)}; // do something.. }