C# HashSet IsProperSupersetOf() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
HashSet

Definition

In C#, HashSet.IsProperSupersetOf(other) is the strict version of IsSupersetOf(). It returns true only when your set contains every item of other and also has at least one item that other lacks.

With circles: the other circle is entirely inside yours, and yours is bigger. {1, 2, 3} is a proper superset of {1, 2}, but not of {1, 2, 3}, because there is no extra item. It never changes the set.

This is an instance member of HashSet<T> (System.Collections.Generic). Call it on a set variable, such as numbers.IsProperSupersetOf(...). A HashSet<T> is a class, so two variables can share one set. It keeps unique items only and does not promise any order.

Syntax

Call IsProperSupersetOf on the bigger set and pass the smaller collection.

C#
HashSet<int> big = new HashSet<int> { 1, 2, 3 };

bool a = big.IsProperSupersetOf(new int[] { 1, 2 });     // true: has everything, plus 3
bool b = big.IsProperSupersetOf(new int[] { 1, 2, 3 });  // false: equal, nothing extra
bool c = big.IsSupersetOf(new int[] { 1, 2, 3 });        // true: equal is allowed here
CallWhat it does
big.IsProperSupersetOf(small)true when big holds all of small and at least one more item.
big.IsProperSupersetOf(equalSet)false, because there is no extra item.
nonEmpty.IsProperSupersetOf(new int[0])true: any non-empty set is a proper superset of an empty collection.

Passing null throws ArgumentNullException. An empty set is never a proper superset of anything. a.IsProperSupersetOf(b) is the same question as b.IsProperSubsetOf(a).

Library declarations
C#
public bool IsProperSupersetOf(IEnumerable<T> other);

Parameters

ParameterDescription
otherRequired. The collection that must be fully inside the set. It must not be null.

Return Value

Return ValueDescription
booltrue if the set contains every item of other and also has at least one item that other does not have. Otherwise false.

C# Examples

Example 1 — Compare Proper and Plain Superset

Test a three-number set against a smaller set and against an equal set, with both superset methods.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        HashSet<int> big = new HashSet<int> { 1, 2, 3 };

        Console.WriteLine(big.IsProperSupersetOf(new int[] { 1, 2 }));
        Console.WriteLine(big.IsProperSupersetOf(new int[] { 3, 2, 1 }));
        Console.WriteLine(big.IsSupersetOf(new int[] { 3, 2, 1 }));
        Console.WriteLine(big.IsProperSupersetOf(new int[] { 1, 9 }));
    }
}

How It Works

  1. Bigger by one. big has 1 and 2, plus the extra 3, so the first call is True.
  2. Same items. The array holds 3, 2, 1, which is the same set in another order. Nothing extra means IsProperSupersetOf is False.
  3. Plain superset allows equal. For the same array IsSupersetOf says True. This pair of lines shows the meaning of "proper".
  4. Missing item. The array has a 9 that big lacks, so big does not contain everything and both superset questions would be False.

Example 2 — Empty Sets and Proper Superset

Check an empty collection against a one-item set, and the empty set against everything.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        HashSet<int> one = new HashSet<int> { 1 };
        HashSet<int> empty = new HashSet<int>();

        Console.WriteLine(one.IsProperSupersetOf(new int[0]));
        Console.WriteLine(empty.IsProperSupersetOf(new int[0]));
        Console.WriteLine(empty.IsProperSupersetOf(new int[] { 1 }));
        Console.WriteLine(empty.IsSupersetOf(new int[0]));
    }
}

How It Works

  1. Something versus nothing. one holds an item and the empty array holds none, so one has all of the (zero) items plus an extra one: True.
  2. Empty versus empty. They are equal, so there is no extra item. The answer is False.
  3. Empty cannot be bigger. The empty set cannot contain the item 1, so it is not a superset of {1} at all.
  4. Plain superset differs. For the equal pair, IsSupersetOf on the last line is True, because equal is allowed there.

Example 3 — Detect That a Set Has Grown

Take a snapshot copy, change the set, and use IsProperSupersetOf to see whether the set only gained items.

C#
using System;
using System.Collections.Generic;

class Program {
    static void Main() {
        HashSet<int> scores = new HashSet<int> { 10, 20 };
        HashSet<int> snapshot = new HashSet<int>(scores);

        Console.WriteLine(scores.IsProperSupersetOf(snapshot));

        scores.Add(30);
        Console.WriteLine(scores.IsProperSupersetOf(snapshot));

        scores.Remove(10);
        Console.WriteLine(scores.IsProperSupersetOf(snapshot));
        Console.WriteLine(scores.Overlaps(snapshot));
    }
}

How It Works

  1. Snapshot. new HashSet<int>(scores) copies the set at one moment. Right now both are equal, so the first answer is False.
  2. After Add. scores now has 10, 20, and 30. It holds everything in the snapshot plus 30, so the answer is True.
  3. After Remove. Taking away 10 breaks the "holds everything" rule, so scores is no longer a proper superset, and the answer is False.
  4. Still related. The sets still share 20, so Overlaps in the last line is True. A set can overlap another without being its superset.

Frequently Asked Questions

IsSupersetOf is true when the set contains every item of the other collection, even if they are equal. IsProperSupersetOf also needs the set to have at least one extra item.
false. Equal sets have no extra item, so neither is a proper superset of the other.
No. It has no items, so it can never have an extra one. IsProperSupersetOf on an empty set is always false.
Yes. It holds all of the zero items in the collection, and it has at least one extra item.
They ask the same question from two sides: a.IsProperSupersetOf(b) is true exactly when b.IsProperSubsetOf(a) is true.

Next: IsSubsetOf()

Check whether every item of the HashSet is also in another collection; returns true or false.

IsSubsetOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful