C# HashSet IsProperSubsetOf() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
HashSet

Definition

In C#, HashSet.IsProperSubsetOf(other) is a strict version of IsSubsetOf(). It returns true only when every item of your set is in other and other has at least one extra item.

Say it with circles: your circle is inside the other circle and the other circle is bigger. {1, 2} is a proper subset of {1, 2, 3}, but it is not a proper subset of {1, 2}, because there is nothing extra. The method does not change the set.

This is an instance member of HashSet<T> (System.Collections.Generic). Call it on a set variable, such as numbers.IsProperSubsetOf(...). 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 IsProperSubsetOf on the smaller set and pass the larger collection.

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

bool a = small.IsProperSubsetOf(new int[] { 1, 2, 3 });  // true: inside, with an extra item
bool b = small.IsProperSubsetOf(new int[] { 1, 2 });     // false: equal, nothing extra
bool c = small.IsSubsetOf(new int[] { 1, 2 });           // true: equal is allowed here
CallWhat it does
small.IsProperSubsetOf(big)true when small is inside big and big has more.
small.IsProperSubsetOf(equalSet)false, because an equal collection has nothing extra.
empty.IsProperSubsetOf(nonEmpty)true: the empty set fits in any collection that has at least one item.

Passing null throws ArgumentNullException. The empty set is a proper subset of every non-empty collection, but not of an empty one. Repeats in other are ignored when the method decides what is "extra".

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

Parameters

ParameterDescription
otherRequired. The collection to compare with. It must not be null.

Return Value

Return ValueDescription
booltrue if the set is inside other and other has at least one item the set does not have. Otherwise false.

C# Examples

Example 1 — Compare Proper and Plain Subset

Check a small set against a bigger one and against an equal one, using both IsProperSubsetOf and IsSubsetOf.

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

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

        Console.WriteLine(small.IsProperSubsetOf(bigger));
        Console.WriteLine(small.IsProperSubsetOf(same));
        Console.WriteLine(small.IsSubsetOf(same));
    }
}

How It Works

  1. Inside and smaller. bigger has the extra item 3, so small is a proper subset and the first line is True.
  2. Equal is not proper. same holds exactly 1 and 2 (order does not matter). Nothing extra means IsProperSubsetOf is False.
  3. Plain subset allows equal. The same pair of sets gives True with IsSubsetOf.
  4. The one difference. The two methods only disagree when the sets are equal. That is the whole meaning of "proper".

Example 2 — The Empty Set and Proper Subset

Test the empty set against a collection with items, against another empty one, and in the opposite direction.

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

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

        Console.WriteLine(empty.IsProperSubsetOf(one));
        Console.WriteLine(empty.IsProperSubsetOf(new int[0]));
        Console.WriteLine(one.IsProperSubsetOf(empty));
        Console.WriteLine(empty.IsSubsetOf(new int[0]));
    }
}

How It Works

  1. Empty inside non-empty. The empty set has nothing that could be missing, and one has an extra item (1), so the first line is True.
  2. Empty vs empty. Both are equal, so there is nothing extra and the answer is False. Plain IsSubsetOf in the last line says True for the same pair.
  3. Wrong direction. one has the item 1, but empty cannot hold it, so one.IsProperSubsetOf(empty) is False.
  4. Rule to remember. An empty set is a proper subset of every collection that has at least one item, and of nothing else.

Example 3 — Does the Senior Know Strictly More?

Compare skill sets: a junior set against a senior set that has one more skill, and against a peer with the same skills.

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

class Program {
    static void Main() {
        HashSet<string> junior = new HashSet<string> { "c#", "sql" };
        HashSet<string> senior = new HashSet<string> { "c#", "sql", "azure" };
        HashSet<string> peer = new HashSet<string> { "sql", "c#" };

        Console.WriteLine(junior.IsProperSubsetOf(senior));
        Console.WriteLine(junior.IsProperSubsetOf(peer));
        Console.WriteLine(junior.SetEquals(peer));
    }
}

How It Works

  1. Skills as a set. Each person has a set of skill names. Order does not matter, only which skills are present.
  2. Senior knows more. junior is fully inside senior, and "azure" is extra, so IsProperSubsetOf returns True.
  3. Peer knows the same. peer was written in a different order but holds the same two skills, so there is nothing extra and the answer is False.
  4. Equality check. SetEquals confirms the two sets are the same, which is exactly why the proper check failed.

Frequently Asked Questions

IsSubsetOf is true when every item of the set is in the other collection, even if they are equal. IsProperSubsetOf also needs the other collection to have at least one extra item.
Yes, of any collection that has at least one item. It is not a proper subset of an empty collection.
false. Equal sets have nothing extra, so neither is a proper subset of the other.
No. A HashSet has no order, and the order of items in the other collection does not matter either.
IsProperSupersetOf. a.IsProperSubsetOf(b) is true exactly when b.IsProperSupersetOf(a) is true.

Next: IsProperSupersetOf()

Check whether the HashSet contains every item of another collection and has at least one more.

IsProperSupersetOf() 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.

15 people found this page helpful