

- 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
Group by Operator in C#
<p>Use the group by the operator in C# to separate the results of an expression into parts.</p><p>Let’s say the following is our array −</p><pre class="result notranslate">int[] a = { 5, 10, 15, 20, 25, 30 };</pre><p>Now, using Group by and orderby, we will find the elements greater than 20 −</p><pre class="result notranslate">var check = from element in a orderby element group element by chkGreater(element);</pre><p>The following is the complete code −</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/b4KbPk" rel="nofollow" target="_blank"> Live Demo</a></p><pre class="prettyprint notranslate" style="">using System; using System.Linq; class Demo { static void Main() { int[] a = { 5, 10, 15, 20, 25, 30 }; var check = from element in a orderby element group element by chkGreater(element); foreach (var val in check) { Console.WriteLine(val.Key); foreach (var res in val) { Console.WriteLine(res); } } } static bool chkGreater(int a) { return a >= 20; } }</pre><h2>Output</h2><pre class="result notranslate">False 5 10 15 True 20 25 30</pre>
- Related Questions & Answers
- GROUP BY the number of rows returned by GROUP BY in MySQL?
- Listing all rows by group with MySQL GROUP BY?
- Group by dates in MongoDB?
- HAVING with GROUP BY in MySQL
- Group by element in array JavaScript
- Group objects by property in JavaScript
- MongoDB SELECT COUNT GROUP BY?
- Group by JavaScript Array Object
- How to use order by, group by in c#?
- Difference Between Group By and Order By in SQL
- String compare by == operator in Java
- SELECT DISTINCT vs GROUP BY in MySQL?
- Get rows with GROUP BY in MySQL?
- Group by dates in a MongoDB collection?
- Group-by and Sum in Python Pandas
Advertisements