C# : Array.Except, Getting the index the value had in the original array of the returned array

In the following code, I have to compare two strings, but I have to keep the Index of the original array. Is there a way to do that?

CODE :

        private dataStruct[] compare(string[] older, string[] new_str)
        {
            List <dataStruct> diff = new List<dataStruct>();

            foreach (var str in older.Except(new_str))
            {
                Console.WriteLine(str);
            }
            return diff.ToArray();
        }

Actual output : line 1 line 3...

Expected output : [1]=>line 1 [3]=>line 3...

Thanks!



Read more here: https://stackoverflow.com/questions/64901290/c-sharp-array-except-getting-the-index-the-value-had-in-the-original-array-of

Content Attribution

This content was originally published by JPLEMARABOUT at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: