简体   繁体   English

如何从ArrayList中删除具有特定名称的对象

[英]How to remove object with specific name from ArrayList

I have ArrayList with some objects. 我有一些对象的ArrayList。 My code dynamically adding objects to this ArrayList. 我的代码将对象动态添加到此ArrayList中。 For example, my code adding to ArrayList some buttons. 例如,我的代码向ArrayList添加了一些按钮。

I have some buttons in ArrayList with different names. 我在ArrayList中有一些名称不同的按钮。 I want just one button in ArrayList with specific name. 我只需要特定名称的ArrayList中的一个按钮。

I need something like this: 我需要这样的东西:

if (arrayList.Contains(button.Name = "button1"))
{
    arrayList.Remove(button.Name = "button1");
}

But this code doesn't work. 但是此代码不起作用。

Thanks for help. 感谢帮助。

arrayList = arrayList.Where(x=>x.Name != "button1").ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM