Uniqe List of double array

Hi!

I have an list of double[], I need a way to only add unique arrays to my list.

I like to something like this, the problem is that Contains does not work on arrays
private list<double[]> list = new List<double[]>();

private void Test(double[] data)
{
   if (this.list.Contains(data) == false)
   {
      this.list.Add(data)
   }
}

Open in new window

Any tips?

(no sorting is allowed, the order matters. The compare/contains must be done before adding it to the list)
ulf-jzlAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Meir RivkinFull stack Software EngineerCommented:
you can use Except (linq) on each of the list arrays against the data:
private list<double[]> list = new List<double[]>();

private void Test(double[] data)
{
foreach (var l in this.list){
//if we found double array in the list which produce no difference, than do not add
if(l.Except(data).Count() == 0) return;
}

//if we reached here than no double array was found in the list which matches the data
this.list.Add(data);
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ulf-jzlAuthor Commented:
Nice, thank you! :-)

I created a generic extension method of this.

        public static bool ContainsArray<T>(this IEnumerable<T[]> source, T[] data)
        {
            foreach (var item in source)
            {
                // Check difference of arrays, 0 => No difference, IEnumerable<T[]> already contains the data.
                if (item.Except(data).Count() == 0) return true;
            }

            return false;
        }

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.