Sorry if this is a duplicate, first question here...
I wanna operate on a large array of structs called notes.
But I don't wanna operate on every element of notes. I'm trying to use a filter of an int array (int[]) as to skip quite a few of it as shown in below code.
Note[] notes = new Note[]
{
// Struct stuff ...
};
int[] filter = new int[]{ 4,20,50,367... };
for (int i = 0; i < notes.Length; i++)
{
bool flag = false;
for (int j = 0; j < filter.Length; j++)
{
if (i == filter[j])
{
flag = true;
break;
}
}
if (flag) continue;
// Do something on notes[i]
}
The problem is, the code will run really slow (I think) when both notes array and filter array expands. So, is there a better and faster way to do this? Note that the size of filter can be anything based on other conditions
if (notes[i] == filter[j])instead ofif (i == filter[j])?if (notes[i] == filter[j])shouldn't it cause an error since (struct == int)??