-1

How would I be able to check that the array game is in equal order to the sorted array of positions? The array should be in the order: 2A, 2B, 2C, 0, 1A, 1B, 1C for the user to be successful

public static void Maincode()
{
    string[] game = { "1A", "1B", "1C", "0", "2A", "2B", "2C" };
    string[] positions = new string[]
    {
        "2A",
        "2B",
        "2C",
        "0",
        "1A",
        "1B",
        "1C",

    };
    // other code
}
   
Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
  • Can you clarify what you mean by "is in equal order"? Do you mean that the `game` array needs to be the same as the `positions` array for success? What have you tried? Does simply checking if the `i`th element of `game` is equal to the `i`th element of `positions` not work for you? – Pranav Hosangadi Nov 11 '20 at 16:56

2 Answers2

2

If I understand you correctly you could use SequenceEqual from System.Linq to compare if two sequences are equal like that:

game.SequenceEqual(positions) // returns true if sequences are in the same order, otherwise false
gryz
  • 48
  • 4
0

You can try to use Enumerable.SequenceEqual. Or if you wish to practice or make your own algorithm, then try to loop through elements of an array and compare if the elements on current position are equal:

for(int i = 0; i < positions.Length; i++)
{
   if(!game[i].Equals(positions[i])
     Console.WriteLine("Not Equal!");
}
Miraziz
  • 509
  • 7
  • 15