Remove particular element from an array and return indices of other elements I'd like to get the indices of elements of an array with particular element. Is it okay or, or how can I make it even better?

//string Input = "Net Sales,COGS";

int[] numbers = { 0, 1, 2, 3, 4, 5 };
string[] Values = { "Net Sales", "COGS", "COGS%", "Gross Profit", "GP%", "Quantity" };

string[] selectedValues = Input.Split(new char[] { ',' });
selectedIndex = new int[selectedValues.Length];
selectedIndex = selectedValues.Select(n =&gt; Array.IndexOf(Values, n)).ToArray();

for (int i = 0; i &lt; selectedIndex.Length; i++)
    numbers = numbers.Where(val =&gt; val != selectedIndex[i]).ToArray();

selectedIndex = numbers;
First of all your code doesn't compile.

Second, your code doesn't do what you state - "Remove particular element from an array".

Third, what exactly do you mean by "Remove"? You want to set these elements to null or compact your array? In second case what do you need indexes of other elements for (their indexes will change when you compact your array)?

Ok, now lets start with a declaration of a contract:

You want to get a multivalue result: filtered array and indexes of remaining elements.

public struct Result
{
    public readonly string[] FilteredArray;
    public readonly List&lt;int&gt; IndexesOfRemainingElements;

    public Result(string[] filteredArray, List&lt;int&gt; indexesOfRemainingElements)
    {
        FilteredArray = filteredArray;
        IndexesOfRemainingElements = indexesOfRemainingElements;
    }
}


Now, I'd rewrite your method in this way:

static Result FilterArray(string[] array, string[] input)
{
    var remainingElements = array.Where(i =&gt; !input.Contains(i)).ToArray();

    return new Result(remainingElements, 
                      remainingElements.Select(i =&gt; Array.IndexOf(array, i)).ToList());
}


And finally you can call it:

string input = "Net Sales,COGS";
string[] values = { "Net Sales", "COGS", "COGS%", "Gross Profit", "GP%", "Quantity" };

// Split has an override that accepts params char[]
var result = FilterArray(values, input.Split(','));    


Complete example here: https://dotnetfiddle.net/4wbfpC