
- 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 loop through all the elements of an array in C#?
Firstly, set an array and initialize it −
int[] arr = new int[] {34, 56, 12};
To loop through all the elements of an array −
for (int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); }
Let us see the complete code −
Example
using System; public class Program { public static void Main() { int[] arr = new int[] {34, 56, 12}; // Length Console.WriteLine("Length:" + arr.Length); for (int i = 0; i< arr.Length; i++) { Console.WriteLine(arr[i]); } } }
- Related Articles
- How to loop through an array in Java?
- How do we use foreach statement to loop through the elements of an array in C#?
- How to loop through all the iframes elements of a page using jQuery?
- How to loop through all values of an enum in C#?
- Loop through an array in Java
- How to use for each loop through an array in Java?
- Looping through and getting frequency of all the elements in an array JavaScript
- Loop through the Vector elements using an Iterator in Java
- How to use for...in statement to loop through an Array in JavaScript?
- Loop through an index of an array to search for a certain letter in JavaScript
- JavaScript: How to loop through all DOM elements on a page and display result on console?
- How to filter an array from all elements of another array – JavaScript?
- How can I loop through all rows of a table in MySQL?
- How do you loop through a C# array?
- Recursively loop through an array and return number of items with JavaScript?

Advertisements