📌  相关文章
📜  c# 按钮单击获得最后一个值 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:03.985000             🧑  作者: Mango

代码示例1
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..
}