Home > DeveloperSection > Forums > Comparing array values with each other
Manoj Bhatt
Manoj Bhatt

Total Post:153

Points:1079
Posted on    August-19-2014 3:23 AM

 C# C# 
Ratings:


 1 Reply(s)
 743  View(s)
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.



Pravesh Singh

Total Post:411

Points:2881
Posted on    August-19-2014 3:40 AM

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");

   }

 }


Don't want to miss updates? Please click the below button!

Follow MindStick