Right now, I have two char
arrays, foo1[]
and foo2[]
. When I convert them to string and output to the console, they BOTH appear as
You are possibly looking for:
foo2.SequenceEqual(foo1)
you can make a function of yours which will be faster then first converting char[] to string then compare two strings. 1. First compare length of the arrays if they are not equal return false. 2. start looping through and compare each char, If you find any diff return false else after the loop return true.
if(foo1.Length != foo2.Length){ return false;}
for(int i=0;i<foo1.Length;i++){
if(foo1[i] != foo2[i]){ return false;}
}
return true;
string s = new string(foo1);
string t = new string(foo2);
int c = string.Compare(s, t);
if(c==0){
//its equal
}
I think you can use the SequenceEquals to compare the arrays, even though checking both lengths at first has better performance.
foo1.ToList().Intersect(foo2.ToList())