简体   繁体   中英

Remove object from List

My List is

public List<BaseHomePage.QueueListItem> QueueDataSource
   {
    get { return this._queueDataSource; }
    set { this._queueDataSource = value; }
   }

and I want to remove the object from the list,my code is

for (int i = 0; i < _queueDataSource.Count; i++)
{
    object queue = _queueDataSource[i];

    if (objQuery.BranchOutQueue)
    {
        this._queueDataSource.Remove(queue);   //Here I want to getting error
    }
}

Error : The best overload method match for system.collections.Generic.List.Remove(BaseHome.QueueList) has some invalid arguments

Instead of using object use var .

var queue = _queueDataSource[i];

Or to be specific you can use:

BaseHomePage.QueueListItem queue = _queueDataSource[i];

The reason you are getting the error is that Remove expects parameter of the same type as of List, since you are getting the object retruned in type object its not compatible.

Just use the RemoveAt instead base from the object

     for (int i = 0; i < _queueDataSource.Count; i++)
        {
            if (IsSuccess)
             _queueDataSource.RemoveAt(i)
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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