How to Find No of Duplicates in an Array of Integers

I have An array of integers {100,50,30,100,20,30,50,10,5}

Can any one help in this to find the Same No’s Count…?


What is expected result?
If it’s 3, the following will work.


arrInt.GroupBy(Function(i) i).Count(Function(g) g.Count>1)


Thanks for your response @Yoichi but I have only 2 duplicates in my array how it was giving 3 as result.

i need the result as how many 100’s are same (i.e. That count)… 50’s are same (i.e. That count). 20’s are same (i.e. That count)…


Please try this

Arr.GroupBy(function(x) x).where(function(x) x.Count>1).ToDictionary(function(g) g.Key.ToString,function(g) g.Count.Tostring)

This would give you dictionary output with the value and the count…make sure to create a dictionary of string and string and initialize with New dictionary(of string,string)



Can you try the following sample?

dict = arrInt.GroupBy(Function(i) i).Where(Function(g) g.Count>1).ToDictionary(Function(g) g.Key,Function(g) g.Count) (2.6 KB)


Thanks a lot @Anil_G :star_struck: :grinning:

1 Like

Thank you For your valuable time its working :grinning:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.