
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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(); } } }
- Related Articles
- How to define an array class in C#?
- How to define the rank of an array in C#?
- How to define a rectangular array in C#?
- How to define an array size in java without hardcoding?
- How to define a single-dimensional array in C Sharp?
- How to define an enumerated type (enum) in C++?
- How to declare an array in C#?
- How to initialize an array in C#?
- How to sort an array in C#?
- How to define constants in C++?
- How to define methods in C#?
- How to define namespaces in C#?
- How to define variables in C#?
- How to initialize elements in an array in C#?
- How to sort an array of dates in C/C++?

Advertisements