Code inspection: Possibly unintended linear search in set
This inspection reports calls to Contains with an explicit comparer on a set type such as HashSet<T> or ISet<T>. That call goes through LINQ and can turn a fast set lookup into a linear search.
Example
using System;
using System.Collections.Generic;
using System.Linq;
var set = new HashSet<string>();
Console.WriteLine(set.Contains("value", StringComparer.OrdinalIgnoreCase));
using System;
using System.Collections.Generic;
var set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
Console.WriteLine(set.Contains("value"));
How to fix it
There is no dedicated quick-fix for this inspection. Typical fixes are to create the set with the comparer you need, or use the normal instance Contains call when the set already has the correct comparer.
01 April 2026