Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity get max occurrence in list

using System.Linq;

# first the max repeated elements
var maxRepeatedItem = prod.GroupBy(x => x)
                          .MaxBy(x => x.Count())
                          .First().Key;

# all the max repeated elements
var grouped = prod.ToLookup(x => x);
var maxRepetitions = grouped.Max(x => x.Count());
var maxRepeatedItems = grouped.Where(x => x.Count() == maxRepetitions)
                              .Select(x => x.Key).ToList(); 
 
PREVIOUS NEXT
Tagged: #unity #max #occurrence #list
ADD COMMENT
Topic
Name
8+9 =