- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the differences between a dictionary and an array in C#?
Dictionary
Dictionary is a collection of keys and values in C#. Dictionary is included in the System.Collection.Generics namespace.
To declare a Dictionary −
IDictionary<int, int> d = new Dictionary<int, int>();
To add elements −
IDictionary<int, int> d = new Dictionary<int, int>(); d.Add(1,97); d.Add(2,89); d.Add(3,77); d.Add(4,88);
Array
Array stores a fixed-size sequential collection of elements of the same type. It consists of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.
To define Arrays −
int[] arr = new int[5];
To initialize and set elements to Arrays.
int[] arr = new int[10] {3, 5, 35, 87, 56, 99, 44, 36, 78};
Advertisements
To Continue Learning Please Login
Login with Google