Click or drag to resize

RankedSetTRemoveWhere Method

Removes all items that match the condition defined by the supplied predicate from the set.

Namespace:  Kaos.Collections
Assembly:  KaosCollections (in KaosCollections.dll) Version: 4.2.0.0
Syntax
C#
public int RemoveWhere(
	Predicate<T> match
)

Parameters

match
Type: SystemPredicateT
The condition of the items to remove.

Return Value

Type: Int32
The number of items removed from the set.
Exceptions
ExceptionCondition
ArgumentNullExceptionWhen match is null.
Remarks
This is a O(n log m) operation where m is the number of items removed and n is Count.
Examples

Here, this method is is used to remove strings containing a space.

C#
using System;
using Kaos.Collections;

namespace ExampleApp
{
    class RsExample01
    {
        static bool IsPolynymous (string name) => name.Contains (" ");

        static void Main()
        {
            var musicians = new RankedSet<string> (StringComparer.InvariantCultureIgnoreCase);

            foreach (var m1 in new string[] { "Falco", "k.d. lang", "Madonna", "Tom Petty",
                                              "Joni Mitchell", "Grimes", "Warren Zevon" })
                musicians.Add (m1);

            Console.WriteLine ("Candidates:");
            foreach (var item in musicians)
                Console.WriteLine ($"  {item}");

            musicians.Remove ("Falco");
            musicians.RemoveWhere (IsPolynymous);
            musicians.RemoveRange (1, musicians.Count-1);

            Console.WriteLine ("\nFavorite:");
            foreach (var item in musicians)
                Console.WriteLine ($"  {item}");
        }

        /* Output:

        Candidates:
          Falco
          Grimes
          Joni Mitchell
          k.d. lang
          Madonna
          Tom Petty
          Warren Zevon

        Favorite:
          Grimes

        */
    }
}
See Also