Friday, March 14, 2008

Array.FindAll

To extract from array a sub array by a condition can be used next way:

List<int> subList = new List<int>();
for (int i = 0; i < data.Length; i++)
{
if (data[i] >= minValue && data[i] <= maxValue)
subList.Add(data[i]);
}
return subList.ToArray();

Bug csharp it is suggested to use method Array.FindAll by next way:

return Array.FindAll(data, delegate(int value)
{
return value >= minValue && value <= maxValue;
});

Reference:

Array..::.FindAll<(Of <(T>)>) Generic Method

No comments: