Click or drag to resize

RankedSetTRemoveRange Method

Removes an index range of items from the set.

Namespace:  Kaos.Collections
Assembly:  KaosCollections (in KaosCollections.dll) Version: 4.2.0.0
Syntax
C#
public void RemoveRange(
	int index,
	int count
)

Parameters

index
Type: SystemInt32
The zero-based starting index of the range of items to remove.
count
Type: SystemInt32
The number of items to remove.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionWhen index or count is less than zero.
ArgumentExceptionWhen index and count do not denote a valid range of items in the set.
Remarks
This is a O(log n) operation where n is Count.
Examples

Here, this method is is used to truncate a set.

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