---
title: "Comparing array values with each other"  
description: "Comparing array values with each other"  
author: "Manoj Bhatt"  
published: 2014-08-19  
updated: 2014-08-19  
canonical: https://www.mindstick.com/forum/2062/comparing-array-values-with-each-other  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Comparing array values with each other

Comparing [array values](https://www.mindstick.com/forum/159317/merge-json-array-values-across-multiple-rows-in-mysql) with each other

I want to [compare two](https://www.mindstick.com/forum/34476/specific-cast-is-not-valid-in-linq-query-when-compare-two-tables) [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) [arrays](https://www.mindstick.com/articles/11955/arrays-and-its-limitations) and then print the [equals](https://www.mindstick.com/interview/33895/difference-between-and-equals-method-in-c-sharp) out. I tried the [Intersect](https://www.mindstick.com/forum/34040/use-intersect-in-sql-server) [method](https://www.mindstick.com/forum/166/webservice-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](https://www.mindstick.com/interview/34427/explain-the-output-in-angular) always returns true with this if-statement.

## Replies

### Reply by Pravesh Singh

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");   } }
```


---

Original Source: https://www.mindstick.com/forum/2062/comparing-array-values-with-each-other

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
