COMPARING ARRAY VALUES WITH EACH OTHER

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
C# 
C#
 971  View(s)
Ratings:
Rate this:

Comparing array values with each other

I want to compare two integer arrays and then print the equals out. I tried the Intersect method:

var checkingDuplicates = boughttickets.Intersect(winningtickets).Any();

and then used a if-statement:

if (checkingDuplicates == false)

{

    Console.WriteLine("Sorry, You didn't win anything");

}

else

{

    Console.WriteLine(checkingDuplicates);

}

However, the output always returns true with this if-statement.

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Comparing array values with each other

    Hi Manoj, 

    First i would say read the documentation. From your comment above, you can not call .toString() on IEnumerable withou defining .tostring implementation. Try this

    var checkingDuplicates = boughttickets.Intersect(winningtickets);

    if (!checkingDuplicates.Any())

     {

       Console.WriteLine("Sorry, You didn't win anything");

     }

     else

     {

       foreach(TICKET checkingDuplicate in checkingDuplicates)

       {

        Console.WriteLine("FETCH AND PRINT YOUR TICKET INFORMATION FROM TICKET OBJECT/CLASS");

       }

     }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!