
- 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 a single-dimensional array in C Sharp?
An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations.
To define a single-dimensional array −
int[] runs = new int[10];
Let us now initialize the array in the same line −
int[] runs = new int[5] {125, 173, 190, 264, 188};
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[5] {125, 173, 190, 264, 188}; int i,j; for (j = 0; j < 5; j++ ) { Console.WriteLine("Innings score of Cricketer[{0}] = {1}", j, runs[j]); } Console.ReadKey(); } } }
Output
Innings score of Cricketer[0] = 125 Innings score of Cricketer[1] = 173 Innings score of Cricketer[2] = 190 Innings score of Cricketer[3] = 264 Innings score of Cricketer[4] = 188
- Related Articles
- Single dimensional array in Java
- How to Map multi-dimensional arrays to a single array in java?
- How to define multi-dimensional arrays in C#?
- How to define multi-dimensional arrays in C/C++?
- Single dimensional array vs multidimensional array in JavaScript.
- How to declare a two-dimensional array in C#
- How to define a rectangular array in C#?
- Dimensional Array in C#?
- How to define an array in C#?
- How do I sort a two-dimensional array in C#
- How to copy the entire ArrayList to a one-dimensional Array in C# ?
- How to access elements from multi-dimensional array in C#?
- 4 Dimensional Array in C/C++
- Passing two dimensional array to a C++ function
- How to define an array class in C#?

Advertisements