C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Count Number of Duplicate Values in an Array in C#
WhatsApp
Nanhe Siddique
Jun 12
2015
56.8
k
0
1
public
static
void
Main()
{
int
[] array =
new
int
[10];
for
(
int
i = 0; i < array.Length; i++)
{
array[i] = Convert.ToInt32(Console.ReadLine());
}
var dict =
new
Dictionary <
int
,
int
> ();
foreach
(var value
in
array)
{
if
(dict.ContainsKey(value)) dict[value]++;
else
dict[value] = 1;
}
foreach
(var pair
in
dict)
Console.WriteLine(
"Value {0} occurred {1} times"
, pair.Key, pair.Value);
Console.ReadKey();
}
Count number of duplicate value
Duplicate values in C#
C# Programming
Up Next
Count Number of Duplicate Values in an Array in C#