
- 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 is an array initialized 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
- C Program on two-dimensional array initialized at run time
- How is an array declared in C#?
- Why is a C++ pure virtual function initialized by 0?
- Can a final variable be initialized when an object is created in Java?
- What is an array in C#?
- When are static C++ class members initialized?
- How are C++ Local and Global variables initialized by default?
- What is an array class in C#?
- When do function-level static variables get initialized in C/C++?
- Is it possible to resize an array in C#
- Check if an array is stack sortable in C++
- What is an array of structures in C language?
- How to declare an array in C#?
- How to define an array in C#?
- How to initialize an array in C#?
Advertisements