int[] nums = { 3, 1, 2 };ornew int[5]nums.Length,nums[0],nums[^1](last element)Array.Sort(),Array.Reverse(),Array.IndexOf()- Ranges:
nums[1..3] - 2D:
int[,] grid = { {1, 2}, {3, 4} };
C# Arrays
Single and multi-dimensional arrays.
✍️ 2 exercises in this lessonKey Takeaways: C# Arrays
Mastering C# Arrays helps you write clean and reliable C# code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
C# Arrays Code Example
C#int[] marks = { 72, 95, 58, 88 };
Array.Sort(marks);
Console.WriteLine(string.Join(", ", marks));
Console.WriteLine($"Lowest {marks[0]}, highest {marks[^1]}");
Console.WriteLine(string.Join(", ", marks[1..3]));
Console.WriteLine(marks.Sum());
int[,] grid = { { 1, 2, 3 }, { 4, 5, 6 } };
Console.WriteLine(grid[1, 2]);
Output
58, 72, 88, 95 Lowest 58, highest 95 72, 88 313 6
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
C# Arrays Practice Exercises
Check what you learned in “C# Arrays”.
/ 2 solved
Fill in the blank
Get the last element with the index-from-end operator.
int last = marks[ ];
✓ Correct!
Not quite. Try again.
Multiple choice
Which method sorts an array in place?
✓ Correct!
Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services