mono - How to compare arrays for equality in C#? -
in c++, if want check if 2 arrays equal (in terms of content), can do:
#include <vector> #include <cassert> using namespace std; int main (int argc, char * const argv[]) { vector<int> a; a.push_back(5); a.push_back(6); a.push_back(7); vector<int> b = a; // copies array a's contents array b assert( == b ); // compares content of array , b 1 element @ time return 0; } how can achieve same thing in c# without writing own comparison for-loop?
3 links found far, though i'm not sure if outdated:
- jon skeet's answer (rolling own loop)
- using linq (use sequenceequal() or intersect() -- supported in mono?)
- msdn blogs -- array.equals -- i'm surprised comparing array content not provided out of box. =s
i'm c# newbie , i'm using mono.
bool equals = array1.orderby(a => a).sequenceequal(array2.orderby(a => a)); easy way
Comments
Post a Comment