
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- 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
- C# program to print unique values from a list
- Remove duplicates from a List in C#
- Java Program to Remove Duplicates from an Array List
- How to print Floyd’s triangle (of integers) using C program?
- Javascript Program For Removing Duplicates From A Sorted Linked List
- C# program to print all sublists of a list
- Remove Duplicates from Sorted List in C++
- 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
- Remove Duplicates from Sorted List II in C++

Advertisements