List.equals does not work

Hello,

I am trying to implement a simple alogrithm in my game where I need to use lists.

I am not able to fetch the right output comparing two lists for equality.

List<string> l1 = new List<string>();
List<string> l2 = new List<string>();
 l1.Add ("Red");
l1.Add ("Blue");
l2.Add ("Red");
l2.Add ("Blue");
print (l1.Equals (l2));

result i get here is false! any ideas?

If you’re open to using the Linq library here are a couple things you could use.

Intersect
Gets which items are the same in both lists

Except
Gets which items aren’t the same in both lists

Then you could compare the count of the intersected/excepted list to the original list count.

Thank you so much. Got it working now.

Just so that I am not confused in the future, list.equals does give out if two list are equal in elements and size right… in general outside of Unity because I remember using that in Java. It won’t work in Unity for the reasons you explained. Thanks!!