C#


 

C# 2nd highest number print from array

static void Main() { // Create an array of integers int[] numbers = { 10, 5, 17, 8, 25, 3, 12 };

        // Find the maximum number using LINQ's Max method int maxNumber = numbers.Max(); // Sort the array in descending order Array.Sort(numbers, (a, b) => b.CompareTo(a)); // Check if there are at least two elements in the array if (numbers.Length >= 2) { // Print the second highest number Console.WriteLine("The second highest number is: " + numbers[1]); } else { Console.WriteLine("The array does not have a second highest number."); } }

------------------

using System; using System.Threading; using System.Threading.Tasks; class Program { static void Main() { // Create an array of integers int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Create a parallel loop using Parallel.ForEach Parallel.ForEach(numbers, number => { // Simulate some processing Thread.Sleep(100); // Print the square of the number Console.WriteLine($"{number} squared is {number * number}"); }); Console.WriteLine("Parallel processing is complete."); } }

Comments

Popular posts from this blog

Travel RESUME CV

PTE