var distinct = array.SelectMany(a => a).Distinct().ToArray();
This simply flattens the nested arrays into a sequence and calls Distinct
to find the distinct elements. The call to ToArray
may be somewhat inefficient since the length of the distinct sequence is not known in advance. This is unlikely to be a problem if there are only a small number of distinct elements.
If you have a large input array, it may be quicker to copy the elements copy the elements into a new array, perform a radix sort and then iterate over the sorted array while skipping equal elements.