I’m confused about Content and Remove items in a List. Can someone teachme some words about pls?
items.Content(BsonItem) return a bool if the item match(_id) or if the item is a BsonItem(same type)?
items.Remove(BsonItem) remove the BsonItem passed and matching or is removing the first BsonItem in the collection found?
In these cases :
How i can get if a BsonItem is existen already in my collection ?
How i can remove a BsonItem in a collection without know the position.?
I searching to pass a BsonItem from one List to another based in some criterials. Thanks
var itemtoReturn = items[RandomItem(items.Count())];
if (!show.Contains(itemtoReturn) && show.Count() < items.Count())
{
returned.Add(itemtoReturn);
//removed from the items
items.Remove(itemtoReturn);
}
I’m guessing you meant to ask if Items.Contains(BsonItem) returns a bool if items match based on your code sample?
.Contains(BsonItem) will check for equality based on BsonItem’s implementation of IEquatable. By default it will look for the same instance of BsonItem, assuming BsonItem is a reference type.
If you want to check on something like BsonItem.id == anotherBsonItem.id, you could use a Where() like so:
If you don’t want to implement IEquatable yourself, you could also use this to check for existence:
Sidenote: If you decide to implement IEquatable, you have to deal with GetHashCode as well