All the arithmetics like 20
, 10 + 10
, 5 + 15
, 2 + 18
and 18 + 2
will be computed at the compile time,
so at the run time you can't distinguish 20
's from one another.
However, you may change design from sums (18 + 2
) into just tems (18, 2
):
// please, notice commas instead of +'s
var lists = new List<List<int>>() {
new List<int> { 20 },
new List<int> { 10, 10 },
new List<int> { 5, 15 },
new List<int> { 2, 18 },
new List<int> { 18, 2 },
};
In this case case you can implement duplicates eliminations
// simplest, providing that list doesn't contain null's
for (int i = 0; i < lists.Count; ++i) {
// since we want to compare sequecnes, we shall ensure the same order of their items
var item = lists[i].OrderBy(x => x).ToArray();
for (int j = lists.Count - 1; j > i; --j)
if (item.SequenceEqual(lists[j].OrderBy(x => x)))
lists.RemoveAt(j);
}
Test
var result = lists.Select(line => string.Join(" + ", line));
Console.Write(string.Join(Environment.NewLine, result));
The output is
20
10 + 10
5 + 15
2 + 18
>](http://stackoverflow.com/questions/12784788/c-sharp-remove-duplicates-from-listlistint)
– Tinwor Oct 24 '16 at 07:33int`, so the last two are the same, 20 in both cases
– Pikoh Oct 24 '16 at 07:46