James Michael Hare

...hare-brained ideas from the realm of software development...
posts - 137 , comments - 1099 , trackbacks - 0

My Links

News

Welcome to my blog! I'm a Sr. Software Development Engineer in Seattle, WA. I've been doing C++/C#/Java development for over 18 years, but have definitely learned that there is always more to learn!

All thoughts and opinions expressed in my blog and my comments are my own and do not represent the thoughts of my employer.

Blogs I Read

MCC Logo MVP Logo

Follow BlkRabbitCoder on Twitter

Tag Cloud

Archives

Post Categories

LINQ

There are 36 entries for the tag LINQ
C#/.NET Fundamentals: Three Tech.Pro Tutorials
I know I’ve been a bit quiet on my blog lately. I’ve still been adjusting to my new life in Seattle and learning different technologies for my new job. It’s been a lot of fun, but has left me with precious little free time! That said, a few months ago I was invited to throw together some tutorials on Tech.Pro as part of their startup series, so I decided to give it a go. Their site has a nice collection of tutorials of various skill level ratings from several different authors. These were the tutorials ......

Posted On Thursday, May 2, 2013 9:09 PM | Comments (0) |

C#/.NET Little Wonders: Extension Methods Demystified
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. I have had the pleasure to program in a variety of programming languages throughout the years including the trifecta of C++, Java, and C#. It's often interesting how these three languages are so similar and yet have such key differences as well. Each of them has ......

Posted On Friday, March 8, 2013 12:47 AM | Comments (6) |

C#/.NET Little Wonders: The St. Louis Days of .NET Presentations
Here are the slides for my three presentations this year for the St. Louis Days of .NET 2012. Enjoy them and feel free to share them as you see fit! If you enjoy these presentations, please check out the entire index of my C# Little Wonders, Little Pitfalls, and Fundamentals blog posts which can be found here. Update: Source has been updated to include Saturday’s presentations as well, also added more comments. Also, each of the presentations will have a small pool ball in the lower right hand corner ......

Posted On Friday, August 3, 2012 12:19 AM | Comments (0) |

C#/.NET Little Wonders: The Joy of Anonymous Types
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. In the .NET 3 Framework, Microsoft introduced the concept of anonymous types, which provide a way to create a quick, compiler-generated types at the point of instantiation. These may seem trivial, but are very handy for concisely creating lightweight, strongly-typed ......

Posted On Thursday, June 21, 2012 7:53 PM | Comments (10) |

C#/.NET Little Wonders: Use Cast() and OfType() to Change Sequence Type
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. We’ve seen how the Select() extension method lets you project a sequence from one type to a new type which is handy for getting just parts of items, or building new items. But what happens when the items in the sequence are already the type you want, but the sequence ......

Posted On Thursday, June 7, 2012 5:48 PM | Comments (6) |

C#/.NET Little Wonders: Select() and Where() with Indexes
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. We’ve talked about the Select() and Where() LINQ extension methods before. The Select() method lets you project from the source type to a new type, and the Where() method lets you filter the list of items to the ones you are interested in. Most people know of these ......

Posted On Thursday, May 17, 2012 7:11 PM | Comments (4) |

C#/.NET Little Wonders: The Enumerable.Repeat() Static Method
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. So last week we covered the Enumerable.Range() method in the System.Linq namespace, which gives us a handy way to generate a sequence of integers to either use directly, or to feed into a more complex expression. Today we’re going to look at another static method ......

Posted On Thursday, May 3, 2012 7:21 PM | Comments (15) |

C#/.NET Little Wonders: The Enumerable.Range() Static Method
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Thanks for all of your patience while I’ve been dealing with other matters these last few weeks. I didn’t want to let my post slide a third week, so I decided to say a few words about a small static method in the Enumerable class from System.Linq. Using Range() ......

Posted On Thursday, April 26, 2012 7:11 PM | Comments (2) |

C#/.NET Little Wonders: Skip() and Take()
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. I’ve covered many valuable methods from System.Linq class library before, so you already know it’s packed with extension-method goodness. Today I’d like to cover two small families I’ve neglected to mention before: Skip() and Take(). While these methods seem so ......

Posted On Thursday, March 29, 2012 5:58 PM | Comments (3) |

C#/.NET Little Wonders: Of LINQ and Lambdas - A Presentation
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Today I’m giving a brief beginner’s guide to LINQ and Lambdas at the St. Louis .NET User’s Group so I thought I’d post the presentation here as well. I updated the presentation a bit as well as added some notes on the query syntax. Enjoy! The C#/.NET Fundaments: ......

Posted On Monday, March 19, 2012 5:36 PM | Comments (0) |

C#/.NET Little Wonders–The List<T> Range Methods
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. LINQ has added so many goodies that can be used to query IEnumerable<T> sequences that it can be easy to lose sight of some of the methods that are unique to each of the collection classes. This week, we will look at the range series of methods in the List<T> ......

Posted On Thursday, February 23, 2012 6:01 PM | Comments (5) |

C#/.NET Little Wonders: The SequenceEqual() Method
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. First of all, thanks for all the well-wishers for me and my family, things are starting to settle down a bit, so I hope to be able to continue to blog at least on a bi-weekly basis – and I’m hoping to sprinkle in some C++ blog entries as well. But for today, we’re ......

Posted On Thursday, February 16, 2012 7:14 PM | Comments (8) |

C#/.NET Little Wonders: The Predicate, Comparison, and Converter Generic Delegates
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. In the last three weeks, we examined the Action family of delegates (and delegates in general), the Func family of delegates, and the EventHandler family of delegates and how they can be used to support generic, reusable algorithms and classes. This week I will ......

Posted On Thursday, November 24, 2011 9:03 PM | Comments (3) |

C#/.NET Little Wonders: The Generic Func Delegates
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders posts can be found here. Back in one of my three original “Little Wonders” Trilogy of posts, I had listed generic delegates as one of the Little Wonders of .NET. Later, someone posted a comment saying said that they would love more detail on the generic delegates and their uses, since ......

Posted On Thursday, November 10, 2011 6:17 PM | Comments (7) |

C#/.NET Little Wonders: Searching Strings With Contains(), StartsWith(), EndsWith(), and IndexOf()
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders post can be found here. Two weeks ago I decided to stop my Little Wonders in the String class, but I recanted and decided to do one more before wrapping up String. So today we’ll look at ways to find a out if a given source String has a target String inside of it (and where). IndexOf() ......

Posted On Thursday, October 13, 2011 6:23 PM | Comments (6) |

C#/.NET Little Wonders: Five Easy Sequence Aggregators
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders post can be found here. Today we will look at five easy ways to aggregate sequences. Often times when we’re looking at a sequence of objects, we want to do perform some sort of aggregation across those sequences to find a calculated result from the sequence. The methods we will be looking ......

Posted On Thursday, August 25, 2011 9:05 PM | Comments (5) |

A Trio of Presentations: Little Wonders, StyleCop, and LINQ/Lambdas
This week is a busy week for me. First of all I’m giving another presentation on a LINQ/Lambda primer for the rest of the developers in my company. Of Lambdas and LINQ View more presentations from BlackRabbitCoder Then this Saturday the 25th of June I’ll be reprising my Little Wonders presentation for the Kansas City Developers Camp. If you are in the area I highly recommend attending and seeing the other great presentations as well. Their link is here. Little Wonders View more presentations from ......

Posted On Thursday, June 23, 2011 6:36 PM | Comments (2) |

C#/.NET Little Wonders: Empty(), DefaultIfEmpty(), and Count() Extension Methods
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders post can be found here. On this post I will finish examining the System.Linq methods in the static class Enumerable by examining two extension methods Count() and DefaultIfEmpty(), and one static method Empty(). The Empty() static method How many times have you had to return an empty collection ......

Posted On Thursday, June 2, 2011 7:08 PM | Comments (24) |

C#/.NET Fundamentals: Of Lambdas and LINQ
This is a quick presentation I threw together for a group of developers who requested a quick primer on using lambda expressions and the more common LINQ extension methods. It seemed like a good general knowledge presentation so I decided to upload it to slideshare and reference it here as well. This is not meant to be a comprehensive discussion of everything that lambda expressions and LINQ have to offer, but is just sort of a very basic introduction to help those less familiar with reading and ......

Posted On Tuesday, May 17, 2011 12:27 PM | Comments (9) |

C#/.NET Little Wonders: 5 Easy Ways to Combine Sequences
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. The index of all my past little wonders post can be found here. Today I’m going to look at 5 different ways of combining two sequences together using LINQ extension methods. For the purposes of this discussion, I will split these 5 methods into homogeneous and heterogeneous methods (for lack of better terms). “Homogeneous” combinations ......

Posted On Thursday, May 12, 2011 6:00 PM | Comments (3) |

C#/.NET Little Wonders: The LINQ Set Operations -- they're not just for math!
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. Today we are going to examine the LINQ set operations that are part of the IEnumerable<T> extension methods. Now, most of the time when people think of set operations they think of the math or logic classes they are usually taught in, but really these LINQ methods have a much larger appeal and applicability than just math ......

Posted On Thursday, May 5, 2011 7:13 PM | Comments (12) |

C#/.NET Little Wonders: The ElementAt() and Last() Extension Methods
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can help improve your code by making it easier to write and maintain. Most of my time this week has been spent finishing the current iteration at work and updating a presentation for the Springfield DNUG, so today’s post will be a bit on the lighter side, but I wanted to continue my post series so I thought it would be a good time to quickly mention the ElementAt() and Last() LINQ extension methods. ......

Posted On Thursday, April 28, 2011 7:35 PM | Comments (4) |

C#/.NET Little Wonders: The Any() and All() Extension Methods
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can really help improve your code by making it easier to write and maintain. Today we’re going to look at two more handy LINQ extension methods: the Any() and All() methods. These methods can help you examine an enumerable collection to determine if any, or all, of the items in the collection meet some logical condition. Any() – Checks for at least one match The Any() method is a LINQ extension ......

Posted On Thursday, April 21, 2011 6:55 PM | Comments (18) |

C#/.NET Little Wonders: First() and Single() - Similar Yet Different
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can really help improve your code by making it easier to write and maintain. Today we're going to look at two LINQ extension methods that are both very similar and yet very different. Logically, First() and Single() serve similar purposes, but there is a subtle difference between these two that if you aren't expecting it may give you very different behaviors. First() - Retrieves the first occurrence ......

Posted On Thursday, April 14, 2011 7:09 PM | Comments (16) |

C#/.NET Toolbox: Adding a ToHashSet() Extension Method
This post is another in a series that will just contain little GUCs (Generic Utility Classes) I’ve developed along the way. If these already exist as part of the framework and I’ve overlooked them, feel free to let me know! And if you know of a better way to implement them, do the same! I’m never too old to learn something new (I hope!). I've blogged in the past about how useful the overlooked HashSet class can be (here) and about the very useful ToDictionary(), ToList(), and ToLookup() LINQ extension ......

Posted On Thursday, March 31, 2011 6:21 PM | Comments (1) |

C#/.NET Little Wonders: The ToLookup() LINQ Extension Method
Once again, in this series of posts I look at the parts of the .NET Framework that may seem trivial, but can really help improve your code by making it easier to write and maintain. LINQ has added so many wonderful extension methods to our .NET toolbox! In particular, there are a few methods that are useful for creating a collection from an IEnumerable<T> instance. The ToDictionary() and ToList() extension methods, for example, are handy for taking an IEnumerable<T> and creating a Dictionary ......

Posted On Thursday, March 24, 2011 5:39 PM | Comments (5) |

C#/.NET Little Wonders: The Useful But Overlooked Sets
Once again we consider some of the lesser known classes and keywords of C#. Today we will be looking at two set implementations in the System.Collections.Generic namespace: HashSet<T> and SortedSet<T>. Even though most people think of sets as mathematical constructs, they are actually very useful classes that can be used to help make your application more performant if used appropriately. For more of the "Little Wonders" posts, see the index here. A Background From Math In mathematical ......

Posted On Thursday, February 3, 2011 6:23 PM | Comments (13) |

C#/.NET Fundamentals: Finding an Item’s Index in IEnumerable<T>
Sorry for the long blogging hiatus. First it was, of course, the holidays hustle and bustle, then my brother and his wife gave birth to their son, so I’ve been away from my blogging for two weeks. Background: Finding an item’s index in List<T> is easy… Many times in our day to day programming activities, we want to find the index of an item in a collection. Now, if we have a List<T> and we’re looking for the item itself this is trivial: 1: // assume have a list of ints: 2: var list = ......

Posted On Thursday, January 6, 2011 7:29 PM | Comments (2) |

C#/.NET Fundamentals: Returning an Immutable Collection
Last week we discussed returning immutable POCOs from an enclosing class so that you can prevent someone who asks for your class’s data to mutate it out from under you. Now we’re going to get a little more complex and talk about returning immutable collections from an enclosing class for the same reasons. I will discuss several different methods for returning collections in a read-only fashion with their pros and cons, including performance implications. The Problem Many times you will create a type ......

Posted On Thursday, November 4, 2010 7:04 PM | Comments (7) |

C#/.NET Little Wonders: ToDictionary() and ToList()
The Little Wonders series received so much positive response I decided to make it a recurring theme in my blog as new ones popped in my head. There are two simple, yet great, LINQ extension methods you may or may not know about, but that can really simplify the task of converting collection queries into collections: ToDictionary() and ToList(). Introduction: LINQ and Deferred Execution Depending on your knowledge of LINQ, you may be oblivious as to what many of these query expressions do behind the ......

Posted On Thursday, October 21, 2010 6:42 PM | Comments (31) |

C# Toolbox: A Debuggable, Self-Installing Windows Service Template (2 of 2)
Update: I have now placed the zip containing the source for the end result of part 1 and 2 of this service template here. Two weeks ago I began the series with a discussion on how to make a new C# Windows Service template that is “debuggable” (you can find the article here). I had then intended the next week to follow up with a discussion on how to modify that template to make the service “self-installing”. Unfortunately, with my work schedule I wasn’t able to complete the series last week due to ......

Posted On Thursday, October 7, 2010 4:43 PM | Comments (24) |

C#/.NET Five Final Little Wonders That Make Code Better (3 of 3)
This week is my final entry in my Little Wonders series (posts one and two are here and here). These are those little tips and tricks in .NET (and in particular C#) that may not seem like much, but can help make your code either more concise, maintainable, or performant. Thanks again for all your comments and suggestions on this series, it has been a lot of fun to write, and though I feel I could go on forever with lots more tips and tricks, this will be the last Little Wonders post for a while. ......

Posted On Thursday, September 9, 2010 6:06 PM | Comments (33) |

C# Extension Methods - To Extend or Not To Extend...
I've been thinking a lot about extension methods lately, and I must admit I both love them and hate them. They are a lot like sugar, they taste so nice and sweet, but they'll rot your teeth if you eat them too much. I can't deny that they are useful and handy. After all, one of the major components of the Shared Component library where I work is a set of useful extension methods to help simplify common repetitive tasks. But, I also can't deny that they tend to be overused and abused to willy-nilly ......

Posted On Monday, April 26, 2010 10:44 PM | Comments (20) |

C#: LINQ vs foreach - Round 1.
So I was reading Peter Kellner's blog entry on Resharper 5.0 and its LINQ refactoring and thought that was very cool. But that raised a point I had always been curious about in my head -- which is a better choice: manual foreach loops or LINQ? The answer is not really clear-cut. There are two sides to any code cost arguments: performance and maintainability. The first of these is obvious and quantifiable. Given any two pieces of code that perform the same function, you can run them side-by-side and ......

Posted On Friday, April 23, 2010 6:54 AM | Comments (30) |

More Fun with C# Iterators and Generators
In my last post, I talked quite a bit about iterators and how they can be really powerful tools for filtering a collection of items down to a subset of items. This had both pros and cons over returning a full collection, which, in summary, were: Pros: If traversal is only partial, does not have to visit rest of collection. If evaluation method is costly, only incurs that cost on elements visited. Adds little to no garbage collection pressure. Cons: Very slight performance impact if you know caller ......

Posted On Wednesday, April 21, 2010 10:31 PM | Comments (3) |

Of C# Iterators and Performance
Some of you reading this will be wondering, "what is an iterator" and think I'm locked in the world of C++. Nope, I'm talking C# iterators. No, not enumerators, iterators. So, for those of you who do not know what iterators are in C#, I will explain it in summary, and for those of you who know what iterators are but are curious of the performance impacts, I will explore that as well. Iterators have been around for a bit now, and there are still a bunch of people who don't know what they are or what ......

Posted On Monday, April 19, 2010 10:12 PM | Comments (4) |

Powered by: