How to find most common value in a List/

How can I find the most common value in a List. Example:

private List<int> List= new List<int>();

void Start()
{
     List.Add(1);
     List.Add(1);
     List.Add(3);
     List.Add(2);
     List.Add(3);
     List.Add(1);
     //The answer will be 1.
}

You want a histogram. Hie thee to google. A dictionary of key/count is a good place to start such a thing.

If you don’t use it in Update method, Linq is great for this. Research the GroupBy and Select methods. Also you can find many exact examples for your problem searching in Google.

If you want to do it the hard and manual way, you could create a List<List>. Then iterate through your list, adding a new List to the List<List> for each unique value, and for values already seen you just add to its existing List. Then at the end you just check List.count of each List in the List<List>, and whichever is highest is the most common.