Blog LogoBlog Logo

Tag: LINQ

All tags

Code Review: FirstOrDefault()

I regularly review the code that I maintain. Recently, I've come across code like this fairly often: someCollection.FirstOrDefault().Id I cannot rightly...

— 09 Apr 2015

LINQ: FirstOrDefault without the null check afterwards.

So, I was considering a problem I had that called for a LINQ statement that contains a FirstOrDefault() call. If there was an object returned I wanted a string...

— 28 May 2012

First(OrDefault) Vs. Single(OrDefault)

There are two mechanisms (each with an …OrDefault variant) in LINQ for getting one item out of an enumeration. They are First and Single . There is a...

— 07 Oct 2011

Why should you be returning an IEnumerable

I've seen in many places where a method returns a List<T> (or IList<T> ) when it appears that it may not actually really be required, or even desirable when...

— 19 Jul 2011

Parallelisation Talk Examples – Basic PLINQ

These are some code examples from my introductory talk on Parallelisation showing the difference between a standard sequential LINQ query and its parallel...

— 21 Apr 2011

Building a tag cloud with LINQ

I have a set of blog posts that I’m representing as a List of BlogPost objects. A BlogPost is class I created that represents everything to do with a blog...

— 02 Apr 2011

Monitoring change in XML data (LINQ to XML series - Part 5)

This is the 5th part in a series on LINQ to XML. In this instalment we will look at monitoring changes in XML data in the XML classes added to .NET 3.5. The...

— 19 Jul 2008

Navigating XML (LINQ to XML series - part 4)

In my last few posts on LINQ to XML ( part 1 , part 2 and part 3 ) I've shown you a starter on navigating around XML data. In this post I'll continue to show...

— 22 Jun 2008

Navigating XML (LINQ to XML series - Part 3)

In my last two posts I've been introducing you to the the new XML classes in .NET 3.5. In this post I'll continue that and show you some...

— 18 May 2008

Fizz-Buzz in LINQ

This just occurred to me. It is somewhat pointless, but I thought it was interesting: static void Main( string [] args) { var result = from say in Enumerable...

— 16 Apr 2008

Getting values out of XML in .NET 3.5 (LINQ to XML series part 2)

In my last post I gave a brief introduction to some of the new XML classes available in .NET 3.5. In this post I'll continue that introduction by explaining...

— 12 Apr 2008

Introduction to LINQ to XML

Last year I wrote about the new languages features available in C# 3.0 ( Anonymous Types , Extension Methods , Automatic Properties , A start on LINQ , Object...

— 08 Apr 2008

A start on LINQ

I was at the Microsoft MSDN Roadshow today and I got to see some of the latest technologies being demonstrated for the first time and I'm impressed. Daniel...

— 18 Jun 2007