- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to iterate efficiently through an array of integers of unknown size in C#
To iterate efficiently through an array of integers of unknown size in C# is easy. Let’s see how.
Firstly, set an array, but do not set the size −
int[] arr = new int[] { 5, 7, 2, 4, 1 };
Now, get the length and iterate through an array using for loop −
for (int i = 0; i< arr.Length; i++) { Console.WriteLine(arr[i]); }
Let us see the complete example −
Example
using System; public class Program { public static void Main() { int[] arr = new int[] { 5, 7, 2, 4, 1 }; // Length Console.WriteLine("Length:" + arr.Length); for (int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); } } }
Output
Length:5 5 7 2 4 1
- Related Articles
- Search in a Sorted Array of Unknown Size in C++
- How to create an array of integers in JavaScript?
- C++ Program to Iterate Over an Array
- How to loop through all the elements of an array in C#?
- How to sort an array of integers correctly in JavaScript?
- How to sort an array of integers correctly JavaScript?
- How to iterate through Java List?
- Iterate through elements of HashSet in Java
- Iterate through elements of TreeSet in Java
- How to extend the size of an array in Java
- How to correctly iterate through getElementsByClassName() in JavaScript?
- How to iterate through a dictionary in Python?
- How to iterate through a list in Python?
- How to iterate through a tuple in Python?
- Java Program to Iterate through Elements of HashMap

Advertisements