I have an array of arrays – information about selection in Excel using VSTO, where each element means start and end selection position.
For example,
int[][] selection = { new int[] { 1 }, // column A new int[] { 6 }, // column F new int[] { 6 }, // column F new int[] { 8, 9 } // columns H:I new int[] { 8, 9 } // columns H:I new int[] { 12, 15 } // columns L:O };
Could you please help me to find a way, maybe using LINQ or Extension methods, to remove duplicated elements? I mean: F and F, H:I and H:I, etc.
If you want to use a pure LINQ/extension method solution, then you’ll need to define your own implementation of
IEqualityComparerfor arrays/sequences. (Unless I’m missing something obvious, there’s no pre-existing array or sequence comparer in the BCL). This isn’t terribly hard however – here’s an example of one that should do the job pretty well:The advantage of this is that you can then simply call the following to remove any duplicate arrays.
Hope that helps.