- 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
How to define an array in C#?
To define an array in C# −
int[] runs = new int[10];
Let us now initialize the array in the same line −
int[] runs = new int[5] {99, 92, 95};
The following is an example displaying how to declare, initialize and display an array −
Example
using System; namespace Program { class Demo { static void Main(string[] args) { int[] runs = new int[3] {149, 123, 257}; int j; for (j = 0; j < 3; j++ ) { Console.WriteLine("Score of Cricketer[{0}] = {1}", j, runs[j]); } Console.ReadKey(); } } }
Advertisements