what is the fastest way to generate a unique set in .net 2

前端 未结 6 784
离开以前
离开以前 2021-01-12 21:46

I have what is essentially a jagged array of name value pairs - i need to generate a set of unique name values from this. the jagged array is approx 86,000 x 11 values. It d

6条回答
  •  臣服心动
    2021-01-12 22:02

    How about:

    Dictionary hs = new Dictionary();
    foreach (i in jaggedArray)
    {
        foreach (j in i)
        {
            if (!hs.ContainsKey(j))
            {
                hs.Add(j, 0);
            }
        }
    }
    IEnumerable unique = hs.Keys;
    

    of course, if you were using C# 3.0, .NET 3.5:

    var hs = new HashSet();
    hs.UnionWith(jaggedArray.SelectMany(item => item));
    

    would do the trick.

提交回复
热议问题