How to make a object delete itself from a list. [closed]

*爱你&永不变心* 提交于 2019-12-20 07:56:06

问题


So I have some objects in a list. I want to make my object to have a method that when called will delete itself from the list. How could I do that?


回答1:


Is this a trick question?

public class MyObject
{
    public void RemoveFromList(List<MyObject> list)
    {
        if (list == null)
            return;

        list.Remove(this);
    }
}


来源:https://stackoverflow.com/questions/29738201/how-to-make-a-object-delete-itself-from-a-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!