

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to print duplicates from a list of integers
To print duplicates from a list of integers, use the ContainsKey.
Below, we have first set the integers.
int[] arr = { 3, 6, 3, 8, 9, 2, 2 };
Then Dictionary collection is used to get the count of duplicate integers.
Let us see the code to get duplicate integers.
Example
using System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { int[] arr = { 3, 6, 3, 8, 9, 2, 2 }; var d = new Dictionary < int,int > (); foreach(var res in arr) { if (d.ContainsKey(res)) d[res]++; else d[res] = 1; } foreach(var val in d) Console.WriteLine("{0} occurred {1} times", val.Key, val.Value); } } }
Output
3 occurred 2 times 6 occurred 1 times 8 occurred 1 times 9 occurred 1 times 2 occurred 2 times
- Related Questions & Answers
- Java program to print duplicates from a list of integers
- Python program to print duplicates from a list of integers?
- Python program to remove Duplicates elements from a List?
- Java program to remove duplicates elements from a List
- Java Program to Remove Duplicates from an Array List
- Remove duplicates from a List in C#
- C# program to print unique values from a list
- Python Program to print unique values from a list
- Java program to print unique values from a list
- Java Program to merge duplicates of a List with TreeSet
- C++ Program to Remove Duplicates from a Sorted Linked List Using Recursion
- Python - Ways to remove duplicates from list
- Python Program to Print Nth Node from the last of a Linked List
- Python Program to print element with maximum vowels from a List
- C# program to print all sublists of a list
Advertisements