![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
How are values assigned to arrays in C#?
Declaring an array does not initialize the array in the memory. When the array variable is initialized, you can assign values to the array.
Array is a reference type, so you need to use the new keyword to create an instance of the array. For example, assign the values like the following statement −
double[] price = new double[5]; price[0] = 3245.50; price[1] = 1234.50; price[2] = 8765.50; price[3] = 5784.50; price[4] = 6576.50;
We assigned five values above to the price array. You can assign values to the array at the time of declaration.
double[] price = new double[5] {3245.50, 1234.50, 8765.50, 6576.50;};
Advertisements