Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
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.7
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#