Improving Upon LINQ’s Distinct

Saturday, August 1, 2009

Suppose you have a collection of objects, and you want only the distinct values. You could easily use Linq for this, like that: var items = new {"BMW","Fiat","Ferrari","Fiat"}; var distinctItems = items.Distinct(); This uses the default comparer for the objects in order to see if they’re equal. There’s also another overload, which lets you specify your own comparer. This is its signature: public static IEnumerable<TSource> Distinct<TSource>(this IEnumerable<TSource> source, IEqualityComparer<TSource> comparer); It accepts an IEqualityComparer to compare between items. But the usage of IEqualityComparer is...
tags: ,

WPF Binding, INotifyPropertyChanged and Linq

Friday, August 31, 2007

This is the first of a couple of tips I would like to share reguarding WPF. WPF binding is extremely powerful, but you are bound to run into a few issues, especially if, like myself, you have no WinForms experience. As I was writing my small LiveSpaceToBlogML GUI, I used binding in order to populate an object called ConversionOptions, which pretty much held all the data on the form. The form look something like this (a pretty simplified version, in order to focus on what matters): <Window x:Class="LiveSpaceToBlogML.Window1" xmlns="" xmlns:x="" ...