
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Initialize Elements in an Array in C#
All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.
To initialize an array, first you need to declare it.
int[] marks;
Here,
- int is the datatype
- [] specifies the size of the array
- Marks is the name of the array
Now let us initialize the array using the new keyword.
int[] marks = new int[10];
Now let us assign elements to it.
marks[0] = 96; marks[1] = 90
You can also assign elements like this −
int [] marks = new int[10] { 78, 67, 88, 56, 90, 77, 76, 70, 60, 70};
Advertisements