Author -  Sai gowtham

How to get the second lowest number from a array in C#

Learn, how to get the second Lowest number from a array in C# with the help of examples.

Consider, we have a following array of numbers in our code.

 int[] myArray = new int[] { 4, 24, 1, 20, 3, 40, 2 };

Now, we need to get the second Lowest 2 number from a above array in C#.

To get the second Lowest number from a array, first we need to sort the array using the Array.sort() method then get the second Lowest number using the following index array[1].

Note: In C# arrays are collection of items, we can access it by using the element index. where the first element index is 0, the second element index is 1, etc.

Here is an example:

using System;
using System.Linq;
using System.Collections.Generic;

class GetSecondLowestNumber {
  static void Main() {
    int[] myArray = new int[] { 4, 24, 1, 20, 3, 40, 2 };
    Array.Sort(myArray);
    int secondLowest = myArray[1];
    Console.WriteLine(secondLowest);
  }
}

Output:

2

In the example above, we first sorted the array using the Array.Sort() method by passing the array.

The Array.sort() returns the array in ascending order, so, we can get the second Lowest number by using the myArray[1].

Similarly, we can also get the second Lowest number in C# by using the following Linq syntax.

using System;
using System.Linq;
using System.Collections.Generic;

class GetSecondLowestNumber {
  static void Main() {
    int[] myArray = new int[] { 4, 24, 1, 20, 3, 40, 2 };
    int secondLowest = (from number in myArray
                     orderby number ascending
                     select number).Skip(1).First();
    Console.WriteLine(secondLowest);
  }
}

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY