

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Program to return specified number of elements from the beginning of a sequence
<p>Set an array and arrange it in descending order using OrderByDescending.</p><pre class="result notranslate">int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345};</pre><p>Now, use the Take() method to return specified number of elements from the beginning.</p><pre class="result notranslate">Enumerable<int> units = prod.AsQueryable().OrderByDescending(s => s).Take(2);</pre><p>Let us see the complete code.</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/PuTjtT" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate" style="">using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] prod = { 290, 340, 129, 540, 456, 898, 765, 789, 345}; // Volume of top two products IEnumerable<int> units = prod.AsQueryable().OrderByDescending(s => s).Take(2); foreach (int res in units) { Console.WriteLine(res); } } }</pre><h2>Output</h2><pre class="result notranslate">898 789</pre>
- Related Questions & Answers
- C# Program to return specified number of elements from the end of an array
- C# Program to skip a specified number of elements of an array
- C# Program to skip elements from a sequence as long as the specified condition is true
- C# Program to invert the order of elements in a sequence
- Program to find number of ways we can select sequence from Ajob Sequence in Python
- Program to return number of smaller elements at right of the given list in Python
- Java Program to check the beginning of a string
- Java Program to remove whitespace from the beginning and end of a string
- Program to find the kth missing number from a list of elements in Python
- Python program to delete a new node from the beginning of the doubly linked list
- How to TRIM x number of characters, beginning from the last in MySQL?
- Total number of elements in a specified dimension of an Array in C#
- C# Program to check whether the elements of a sequence satisfy a condition or not
- C# Program to find the sum of a sequence
- Finding sum of sequence upto a specified accuracy using JavaScript
Advertisements