using System.Collections.Generic;
public static void Main()
var counter = new Dictionary<int, int>();
var numbers = new int[] { 1, 9, 4, 5, 8, 5, 4, 1, 9 };
int? singleOccurrence = null;
foreach (var item in numbers)
if (!counter.TryAdd(item, 1))
Console.WriteLine($"Item that only appeared once is: {singleOccurrence}");
Console.WriteLine($"Number of items in the original collection: {numbers.Length}");
Console.WriteLine($"Number of items in the dictionary: {counter.Count}");