- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 to 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};
- Related Articles
- How to initialize an array in C#?
- How to initialize an array in Java
- How to initialize an array in Kotlin with values?
- How to initialize an empty array list in Kotlin?
- How to initialize a rectangular array in C#?
- How to initialize a dynamic array in C++?
- How to initialize an array in JShell in Java 9?
- How to initialize an array using lambda expression in Java?
- How to initialize an empty DateTime in C#
- How to declare, create, initialize and access an array in Java?
- How to access elements from an array in C#?
- How do I declare and initialize an array in Java?
- how to initialize a dynamic array in java?
- How to initialize a boolean array in JavaScript?
- How to initialize a dictionary to an empty dictionary in C#?

Advertisements