0

Is there a way to use an if statement to test an entire array at once by doing something like this:

if(myArray == {1,2,3})
{Debug.Log("This is quick")}

or do I need to iterate through each value in the array like this:

if(myArray[0] == 1 && myArray[1] == 2 && myArray[2] == 3)
{Debug.Log("This is not as quick")}

1 Answers1

1

You should use SequenceEqual.

using System;
using System.Linq;

public class Program
{
    public static void Main()
    {
        int [] myArray = {1,2,3};
        int [] myArray2 = {1,2,4};

        bool result = myArray.SequenceEqual(myArray2);
    }
}
Filimindji
  • 1,453
  • 1
  • 16
  • 23