I have read that it is usually better to use LINQ queries over writing loops. I'm in a situation where I have a HasSet of unsigned integers and the program is allowed to modify the set by removing any one value from the set as long as it is not a certain special value already in the set.

For example if the set contains the values { 1, 2, 3, 4, 5 }, and 3 was the special value the algorithm could remove 1, 2, 4, or 5 from the set.

I have accomplished this behavior by writing code like the following:

HashSet values = new HashSet() { 1, 2, 3, 4, 5 };

uint specialValue = 3;

for (var index = 0; index < values.Count; ++index) {
if (values.ElementAt(index) != specialValue) {
values.Remove(values.ElementAt(index));
break;
}
}

Obviously this is using a loop to accomplish the value removal. How could someone accomplish the same result only a LINQ query?