
- 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
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
- Related Articles
- Array Declarations in Java
- Why do Java array declarations use curly brackets?
- What are JSP declarations? In how many ways we can write JSP declarations?
- What are Declarations?
- Use Declarations in Rust Programming
- What are forward declarations in C++?
- What is typedef declarations in C++?
- Group Use declarations in PHP 7
- Do we need forward declarations in Java?
- MySQL row declarations for ZF?
- C# Multiple Local Variable Declarations
- Understanding CSS Selector and Declarations
- Types of Group Use declarations in PHP 7
- What is the difference between Definitions and Declarations in Compiler design?
- What are the rules for external declarations in JShell in Java 9?

Advertisements