Search This Blog

Friday, September 12, 2025

Array Playground

Features of Array
An array is a fixed-size collection of elements of the same type (e.g., all int, or all string)

//Define int array
var objint = new int[] { 1, 2, 3, 4, 5 };

// Define String Array
var fruits = new string[] { "Zoo", "Potato", "Banana", "Cherry", "Apple" }; // Array initialized with values

// Sorting
Array.Sort(fruits);

//Reverse
Array.Reverse(fruits);

// LinQ to Arrays
var objint2 = new int[] { 1, 5, 7, 23, 15 };
var evenNumbers = objint2.Where(x => x % 2 == 0).ToArray();
var sumNumber = objint2.Sum();
var maxNumber = objint2.Max();


No comments:

Post a Comment