
- 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 find all duplicate elements in an integer array
Firstly, set the array with duplicate elements.
int[] arr = { 24, 10, 56, 32, 10, 43, 88, 32 };
Now declare a Dictionary and loop through the array to get the repeated elements.
var d = new Dictionary < int, int > (); foreach(var res in arr) { if (d.ContainsKey(res)) d[res]++; else d[res] = 1; }
Example
using System; using System.Collections.Generic; namespace Demo { public class Program { public static void Main(string[] args) { int[] arr = { 24, 10, 56, 32, 10, 43, 88, 32 }; 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
24 occurred 1 times 10 occurred 2 times 56 occurred 1 times 32 occurred 2 times 43 occurred 1 times 88 occurred 1 times
- Related Articles
- C Program to delete the duplicate elements in an array
- C# program to print all distinct elements of a given integer array in C#
- C# program to find if an array contains duplicate
- Swift Program to Remove Duplicate Elements From an Array
- Golang Program To Remove Duplicate Elements From An Array
- C program to add all perfect square elements in an array.
- Program to Find Out Median of an Integer Array in C++
- Python program to print the duplicate elements of an array
- How to find the average of elements of an integer array in C#?
- C++ program to find array after removal of left occurrences of duplicate elements
- Find single in an array of 2n+1 integer elements in C++
- Write a Golang program to find duplicate elements in a given array
- C program to find the unique elements in an array.
- Python program to print all distinct elements of a given integer array.
- Print All Distinct Elements of a given integer array in C++

Advertisements