How to compare GameObjects in an array?

I am quite new to Unity and I am making a program for my school project. It is doing to be a classic puzzle game style of matching specific items in a row in order clear them. I have figured how to clear the objects but my only problem is how to detect if two items next to each other are the same. I have used a 2D array which has stored each type of cloned prefab in its corresponding grid position but have found out using commands like:

if (Array[x, y] == Array[x-1, y])

doesn’t work for some reason.

Anyone have any ideas how i could overcome this it would be greatly appreciated.

Well,
this checks the reference of each element if they refer to same gameobject

if you need to check the element prefab type itself use Tags for each type you have and assign them then compare the tags itself


Regards