Comparing array values with each other

Total Post:154

Points:1086

C# 
C#
 1416  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. 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");
       }
     }

      Modified On Apr-04-2018 06:05:25 AM

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.