2
Answers

Array question in c#

kek

kek

16y
2.5k
1
Hi, I got a question. I am trying to check if an array contains values of another array. How can I do this. I am trying to do it by using for and if, but could not do it. So,

int[] firstarray = new int[5];
int[] secondarray = new int[2]; // the length of second array may change in my program so it shoud be new int[length]
firstarray[0]=1;
firstarray[1]=2;
firstarray[2]=3;
firstarray[3]=4;
firstarray[4]=5;
secondarray[0]=1;
secondarray[1]=2;

int[] Resultarray =new int[5];
           

 for (int i=0; i<5; i++)
{
                if (firstarray[i]!=secondarray[0] && firstarray[i]!=secondarray[1]) //the problem is here since the length of secondarray may change, I can not check it like I do here.
                Resultarray[i]=firstarray[i];
                else Resultarray[i]=0;
}

I appriciate any help
Answers (2)