gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
C# compare two byte[]
- User
C# compare two byte[]
- Assistant
To compare two byte arrays in C#, you can use the SequenceEqual() method from the System.Linq namespace. Here's an example:
using System; using System.Linq; class Program { static void Main(string[] args) { byte[] array1 = { 1, 2, 3, 4, 5 }; byte[] array2 = { 1, 2, 3, 4, 5 }; bool areEqual = array1.SequenceEqual(array2); if (areEqual) { Console.WriteLine("The arrays are equal."); } else { Console.WriteLine("The arrays are not equal."); } } }In this example, the
SequenceEqual()method compares each element of the byte arrays and returnstrueif all the elements are equal, andfalseotherwise. The output would be "The arrays are equal." as both arrays have the same values.