Answer the question
In order to leave comments, you need to log in
C#. There are two arrays, how to check the data for a match?
Hello!
There is an array containing a series of data, for example:
string[] array = { "Сайт №1", "Сайт №2", "Сайт №3" };
string[] array = { "Сайт №1", "Сайт №2", "Сайт №3", "Сайт №4" };
Answer the question
In order to leave comments, you need to log in
I don't understand you, but hold on, something is right for you
array2.Except(array1)
array1.Except(array2)
array1.Intersect(array2) // видимо это
The option is stupid - for each element of the first array, loop through the second array and compare.
A smarter option: Sort both arrays, walk through them with two pointers in parallel (If the current elements match, we find a match and move both pointers, otherwise we move the pointer to a smaller element. If one of the arrays is over, that's it).
Best option: Iterate over a smaller array and add its elements into a HashSet<> (via Add()). Then go through the second array and check each element through the Contains() method of the set.
bool isEqual = Enumerable.SequenceEqual(array1, array2);
string[] arr1 = {"a", "bb", "ccc", "zzzz"};
string[] arr2 = {"a", "b", "ccc", "dddd", "ee"};
var result = arr1.Join(arr2, s1 => s1, s2 => s2, (s1, s2) => s1);
int []mas1;
int[]mas2;
for(int i=0;i<mas1.Lenght;i++){
for(int i2=0;i2<mas2.Lenght;i2++){
if(mas1[i]==mas2[i2]){
//Если данные совпали
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question