3

throwing me an error here:

string.Compare(list[], list1[],true); <<<<<<

is causing the error.

string[] list = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "v", "z" };
string[] list1 = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "v", "z" };

int result = string.Compare(list[], list1[], true);

if (result == 0)
{
    Label1.Text += "Two strings are equal";
}
else if (result == 1)
{
    Label1.Text += "Test String1 is greater than Test String2";
}
else if (result == -1)
{
    Label1.Text += "Test String1 is less than Test String2";
}
pickypg
  • 22,034
  • 5
  • 72
  • 84
Nick Kahn
  • 19,652
  • 91
  • 275
  • 406

4 Answers4

6

What about:

 bool areSame = list.SequenceEqual(list1);
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
5

Use SequenceEqual of Linq to check if string arrays are same

http://msdn.microsoft.com/en-us/library/bb348567.aspx

Muhammad Hasan Khan
  • 34,648
  • 16
  • 88
  • 131
2

This will be because string.Compare does not have a signature for accepting arrays.

Also, when you're passing arrays around you do not need to use [] after the variable name as you've done.

There's a great SO Question here that answers the question of how to compare two arrays.

Community
  • 1
  • 1
Jamie Dixon
  • 53,019
  • 19
  • 125
  • 162
1

string.Compare has no overload that takes string arrays.

You will need to write your own function to compare the arrays.

You need to decide the behavior for different length arrays, what to return for different values in the same index etc...

Oded
  • 489,969
  • 99
  • 883
  • 1,009