
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Loop Through All 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]); } } }
Advertisements