

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to initialize 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.
Firstly, declare an array.
int[] rank;
But 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,
int[] rank = new int[5];
You can assign values to an array at the time of declaration.
int[] rank = { 1, 2, 3,4,5};
With that, you can also create and initialize an array in a single line.
int [] rank = new int[5] { 1, 2, 3, 4, 5};
- Related Questions & Answers
- How to initialize an array in Java
- How to initialize elements in an array in C#?
- How to initialize an array in Kotlin with values?
- How to initialize an empty array list in Kotlin?
- How to initialize an array in JShell in Java 9?
- How to initialize an array using lambda expression in Java?
- How to declare, create, initialize and access an array in Java?
- How do I declare and initialize an array in Java?
- Initialize an Array with Reflection Utilities in Java
- How to initialize a boolean array in JavaScript?
- how to initialize a dynamic array in java?
- How to initialize a rectangular array in C#?
- How to initialize a dynamic array in C++?
- How do we initialize an array within object parameters in java?
- How to initialize an empty DateTime in C#
Advertisements