- 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
Array Declarations in C#
The array is a collection of variables of the same type. They are stored contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.
Syntax
To declare an array in C# −
type[] arrayName;
Here,
- type − is the datatype of the array in C#.
- arrayName − The name of the array
- [ ] − Specify the size of the array.
Example
Let us see an example to understand how to declare an array in C# −
using System; namespace MyApplication { class MyClass { static void Main(string[] args) { // n is an array of 5 integers int [] a = new int[5]; int i,j; /* initialize elements of array a */ for ( i = 0; i < 5; i++ ) { a[ i ] = i + 10; } /* output each array element's value */ for (j = 0; j < 5; j++ ) { Console.WriteLine("Element[{0}] = {1}", j, a[j]); } Console.ReadKey(); } } }
Output
Element[0] = 10 Element[1] = 11 Element[2] = 12 Element[3] = 13 Element[4] = 14
Advertisements
To Continue Learning Please Login
Login with Google