This is the example for the usage of Distinct from https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.distinct
List<int> ages = new List<int> { 21, 46, 46, 55, 17, 21, 55, 55 };
IEnumerable<int> distinctAges = ages.Distinct();
Console.WriteLine("Distinct ages:");
foreach (int age in distinctAges)
{
Console.WriteLine(age);
}
/*
This code produces the following output:
Distinct ages:
21
46
55
17
*/
The algorithm seems to be very simple: Iterate the elements. If the current element is unknown, copy it to the result, otherwise discard it.
I want to know if all implementations are required to give this result, or could a future implementation as well output 55, 21, 17, 46?