简体   繁体   中英

Get most used byte array in a byte array in c#?

How can I get the most used byte array from another bytearray? Is there is simple way to do this?

So for example:

the input byte array: 41, 4, 5, 42,4,5,42,4,5,42,2

And then the return: 4, 5, 42

Thanks in advance.

var grouped = prod.ToLookup(x => x);
var maxRepetitions = grouped.Max(x => x.Count());
var allItemsWithEqualMax = grouped.Where(x => x.Count() == maxRepetitions)
                                  .Select(x => x.Key).ToList(); 

Creds: https://stackoverflow.com/a/15184669/496680

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM