Returning a Single Element With LINQ First and LINQ Single

Sometimes you have a list, and you need to return a single element from the list. There are several ways to get the element to return. Below are two ways using LINQ with Lambda expressions. Consider the following class: 1: public class Person 2: { 3: public string Name { get; set; } 4: public [...]

  • Share/Bookmark

Read Users' Comments (0)

GroupBy Multiple Values in LINQ

Here's a simple example to show you how to GroupBy Multiple Values using LINQ. In this example, I am grouping by Age and Sex to find the count of people who have the same age and sex. C# public partial class LINQ : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {       [...]

  • Share/Bookmark

Read Users' Comments (0)

How to Use LINQ GroupBy

The ‘GroupBy’ feature in LINQ is amazing and very powerful. When you use a ‘GroupBy’ in LINQ, internally it calls an extension method which returns a sequence of System.Collections.Generic.IEnumerable<(Of <(IGrouping<(Of <(TKey, TSource>)>)>)>) The GroupBy<(Of <(TSource, TKey>)>)(IEnumerable<(Of <(TSource>)>), Func<(Of <(TSource, TKey>)>)) method returns a collection of IGrouping<(Of <(TKey, TElement>)>) objects, one for each distinct key that [...]

  • Share/Bookmark

Read Users' Comments (0)

How to Read Twitter Feeds With LINQ to XML

Twitter feeds are provided in RSS XML format. This makes it very easy for us to parse out the information we want from a feed using LINQ to XML. For example, if we want to grab the message and date of each Twitter entry, we could use something like this: public class Twitter {     [...]

  • Share/Bookmark

Read Users' Comments (0)