Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6167637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:32:52+00:00 2026-05-23T22:32:52+00:00

static IEnumerable<T> FindUniqueNumbersInCollection<T>(ICollection<T> value) { Dictionary<T, byte> hash = new Dictionary<T, byte>(); foreach (T

  • 0
static IEnumerable<T> FindUniqueNumbersInCollection<T>(ICollection<T> value)
{
    Dictionary<T, byte> hash = new Dictionary<T, byte>();

    foreach (T val in value)
    {
        if (hash.ContainsKey(val)) { hash[val] = 1; continue; }
        hash.Add(val, 0);
    }

    List<T> unique = new List<T>();

    foreach (KeyValuePair<T, byte> kvp in hash)
    {
        if (kvp.Value == 0) unique.Add(kvp.Key);

    }

    return unique;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:32:53+00:00Added an answer on May 23, 2026 at 10:32 pm

    Edit:

    I think this is finally correct. 🙂

    var dict = new Dictionary<T, bool>();
    foreach (var v in value)
        dict[v] = dict.ContainsKey(v);
    foreach (var pair in dict)
        if (!pair.Value)
            yield return pair.Key;  //Algorithmically, as fast as possible
    

    Or if you’d like some LINQ:

    var dict = new Dictionary<T, bool>();
    foreach (var v in value)
        dict[v] = dict.ContainsKey(v);
    return dict.Keys.Where(k => !dict[k]);  //*COULD* be slower on lots of collisions
    

    Or even

    var dict = new Dictionary<T, bool>();
    foreach (var v in value)
        dict[v] = dict.ContainsKey(v);
    return dict.Where(p => !p.Value).Select(p => p.Key); //"Fastest".. but not really
    

    I wouldn’t say it’s "more efficient" than yours (it’s really not — they’re pretty much the same), but it’s definitely shorter.


    If you want overkill efficiency (at the cost of accuracy), you can always use a Bloom Filter!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: public static IEnumerable<dcCustomer> searchCustomer(string Companyname) { TestdbDataContext db = new
public static IEnumerable<T> Get<T>(this IEnumerable<T> source, Func<T, bool> predicate) { foreach (T item in
The following program static IEnumerable<Action> Create() { foreach (var i in Enumerable.Range(0, 2)) {
Take the example here: public static IEnumerable<BigInt> EvenNumbers(IEnumerable<BigInt> numbers) { foreach (BigInt number in
class Foo { public static IEnumerable<int> Range(int start, int end) { return Enumerable.Range(start, end);
This is the definition: public static IEnumerable<TResult> OfType<TResult>(this IEnumerable source); How to replace TResult
Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this
the ToSelectList method I have: public static IList<SelectListItem> ToSelectList<T>(this IEnumerable<T> itemsToMap, Func<T, string> textProperty,
i need Enumarable value from below class but give error public static Enumerable LoadDataByName(string
static Mutex mutex = new Mutex (false, oreilly.com OneAtATimeDemo); static void Main() { //

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.