James Michael Hare

...hare-brained ideas from the realm of software development...
posts - 136 , comments - 1089 , 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

Little Wonders

There are 78 entries for the tag Little Wonders
C#/.NET Little Wonders: Getting Caller Information
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. There are times when it is desirable to know who called the method or property you are currently executing. Some applications of this could include logging libraries, or possibly even something more advanced that may server up different objects depending on who ......

Posted On Thursday, July 25, 2013 10:04 PM | Comments (3) |

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: Explicit Interface Implementation
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. Most of the time in C#, we implement interfaces implicitly. This is by far the simplest method and makes the method available both to consumers of the interface and the implementing type directly. There are times, though, when you may want to implement an interface, ......

Posted On Thursday, February 7, 2013 11:26 PM | Comments (8) |

C#/.NET Little Wonders: The Parallel.Invoke() 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. Many times in software development, we want to invoke several processes at one time and continue when we get all the results back. Obviously, if we were needing to process a sequence of items in a similar matter, we could use PLINQ. Unfortunately, when the things ......

Posted On Thursday, December 20, 2012 8:50 PM | Comments (2) |

Visual Studio Little Wonders: Quick Launch / Quick Access
Once again, in this series of posts I look at features of Visual Studio that may seem trivial, but can help improve your efficiency as a developer. The index of all my past little wonders posts can be found here. Well, my friends, this post will be a bit short because I’m in the middle of a bit of a move at the moment. But, that said, I didn’t want to let the blog go completely silent this week, so I decided to add another Little Wonder to the list for the Visual Studio IDE. How often have you wanted ......

Posted On Thursday, November 15, 2012 7:17 PM | Comments (6) |

Visual Studio Little Wonders: Box Selection
So this week I decided I’d do a Little Wonder of a different kind and focus on an underused IDE improvement: Visual Studio’s Box Selection capability. This is a handy feature that many people still don’t realize was made available in Visual Studio 2010 (and beyond). True, there have been other editors in the past with this capability, but now that it’s fully part of Visual Studio we can enjoy it’s goodness from within our own IDE. So, for those of you who don’t know what box selection is and what ......

Posted On Tuesday, October 30, 2012 7:26 PM | Comments (6) |

C#/.NET Little Wonders: Using ‘default’ to Get Default Values
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’s little wonder is another of those small items that can help a lot in certain situations, especially when writing generics. In particular, it is useful in determining what the default value of a given type would be. The Problem: what’s the default value ......

Posted On Thursday, October 18, 2012 8:29 PM | Comments (2) |

C#/.NET Little Wonders: Static Char 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. Often times in our code we deal with the bigger classes and types in the BCL, and occasionally forgot that there are some nice methods on the primitive types as well. Today we will discuss some of the handy static methods that exist on the char (the C# alias of ......

Posted On Thursday, October 4, 2012 6:51 PM | Comments (13) |

C#/.NET Little Wonders: The Timeout static class
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. When I started the “Little Wonders” series, I really wanted to pay homage to parts of the .NET Framework that are often small but can help in big ways. The item I have to discuss today really is a very small item in the .NET BCL, but once again I feel it can help ......

Posted On Thursday, September 20, 2012 7:52 PM | Comments (4) |

C#/.NET Little Wonders: Interlocked CompareExchange()
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. Two posts ago, I discussed the Interlocked Add(), Increment(), and Decrement() methods (here) for adding and subtracting values in a thread-safe, lightweight manner. Then, last post I talked about the Interlocked Read() and Exchange() methods (here) for safely ......

Posted On Thursday, September 6, 2012 7:14 PM | Comments (11) |

C#/.NET Little Wonders: Interlocked Read() and Exchange()
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. Last time we discussed the Interlocked class and its Add(), Increment(), and Decrement() methods which are all useful for updating a value atomically by adding (or subtracting). However, this begs the question of how do we set and read those values atomically as ......

Posted On Thursday, August 23, 2012 6:03 PM | Comments (3) |

C#/.NET Little Wonders: Interlocked Increment(), Decrement(), and Add()
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. Often times, we need to update a count in a multi-threaded program. This may be an incrementing, decrementing, or adding a value in a thread-safe manner. This post will discuss one of the lightest ways to do this: the Interlocked class. Problem: Increments Are ......

Posted On Thursday, August 9, 2012 8:02 PM | Comments (7) |

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) |

St. Louis Days of .NET Begins Today!
Today is the kickoff for the St. Louis Days of .NET! Today begins the pre-compiler sessions for those who are interested followed by the kick-off gathering at the Bottleneck Blues Bar at the St. Charles Ameristar Casino.This is the 5th year for this conference, and the 3rd year I've been fortunate enough to speak at it. I'll be giving my three talks at the following times (yes, the More Little Wonders is repeated):Friday @ 10:30 - "Little Wonders of .NET"Friday @ 2:50 - "More Little Wonders of .NET"Saturday ......

Posted On Thursday, August 2, 2012 8:45 AM | Comments (2) |

C#/.NET Little Wonders: The Nullable<T> struct
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. There are many times in .NET where we have an instance of a value type that we need to treat as optional. That is, we may want to consider its value as being supplied or missing. The System.Nullable<T> structure in the .NET Framework can be used to represent ......

Posted On Thursday, July 12, 2012 6:10 PM | Comments (12) |

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 (2) |

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++ Little Wonders: The C++11 auto keyword redux
I’ve decided to create a sub-series of my Little Wonders posts to focus on C++. Just like their C# counterparts, these posts will focus on those features of the C++ language that can help improve code by making it easier to write and maintain. The index of the C# Little Wonders can be found here. This has been a busy week with a rollout of some new website features here at my work, so I don’t have a big post for this week. But I wanted to write something up, and since lately I’ve been renewing my ......

Posted On Thursday, March 15, 2012 6:21 PM | Comments (2) |

C#/.NET Little Wonders – The DateTimeOffset struct
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. Anyone who has done any .NET programming has most likely used the DateTime structure at one time or another in their development. It is a handy structure for storing dates, times, or date-times relating to the local time zone (or, alternatively, UTC). That said, ......

Posted On Thursday, March 8, 2012 6:37 PM | Comments (1) |

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 Pitfalls: Implicit Zero To Enum Conversion
C# is a wonderful language for modern programming. While everything in C# has a reason and a place, occasionally there are things that can be confusing for a developer who isn’t aware of what is happening behind the scenes. This is another post in the Little Pitfalls series where I explore these issues; an index of the Little Wonders and Little Pitfalls posts is here. Many times, we create overloaded methods or constructors to allow them to accept different kinds of data. Further, there are times ......

Posted On Thursday, January 26, 2012 6:31 PM | Comments (8) |

C#/.NET Little Pitfalls: Stopwatch Ticks are not TimeSpan Ticks
C# is a wonderful language for modern programming. While everything in C# has a reason and a place, occasionally there are things that can be confusing for a developer who isn’t aware of what is happening behind the scenes. This is another post in the Little Pitfalls series where I explore these issues; an index of the Little Wonders and Little Pitfalls posts is here. This week will be a short post since I’m travelling to Denver for design meetings, and otherwise spending most of my free time celebrating ......

Posted On Thursday, January 12, 2012 6:22 PM | Comments (16) |

C#/.NET Little Wonders: The DateTime TryParse() and ParseExact() 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. A while back I talked about some goodies in DateTime, mostly the properties that let you split out just the date or time. This week, I wanted to look at a couple more methods of the DateTime struct that give you additional control over parsing an input string into ......

Posted On Thursday, January 5, 2012 6:34 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 EventHandler and EventHandler<TEventArgs> 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 two weeks, we examined the Action family of delegates (and delegates in general), and the Func family of delegates and how they can be used to support generic, reusable algorithms and classes. So this week, we are going to look at a handy pair of delegates ......

Posted On Thursday, November 17, 2011 7:20 PM | Comments (9) |

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 (6) |

C#/.NET Little Wonders: The Generic Action 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 3, 2011 8:14 PM | Comments (12) |

C#/.NET Little Wonders & Little Pitfalls: The Complete Collection
I wanted to repost the index of all the Little Wonders and Little Pitfalls posts and presentations so that they would be readily visible for anyone new to these series. I also linked in my C#/.NET Fundamentals presentation "Of Lambdas and Linq", a short primer for those just starting with LINQ and lambda expressions. The Original C#/.NET Little Wonders Trilogy C#/.NET Five Little Wonders (part 1) C#/.NET Five More Little Wonders (part 2) C#/.NET Five Final Little Wonders (part 3) The C#/.NET Little ......

Posted On Monday, October 24, 2011 5:38 PM | Comments (6) |

C#/.NET Little Wonders: TPL Wonders - The Parallel.For() 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. Previously, I had created some posts about the Task Parallel Library’s Concurrent Collections – which are very efficient collections designed for concurrent use with minimal contention – but in this next series of Little Wonders posts, I’d like to explore the parts ......

Posted On Thursday, October 20, 2011 7:43 PM | Comments (3) |

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 & Little Pitfalls: The Complete Collection
I wanted to repost the index of all the Little Wonders and Little Pitfalls posts and presentations so that they would be readily visible for anyone new to these series. I also linked in my C#/.NET Fundamentals presentation "Of Lambdas and Linq", a short primer for those just starting with LINQ and lambda expressions. The Original C#/.NET Little Wonders Trilogy C#/.NET Five Little Wonders (part 1) C#/.NET Five More Little Wonders (part 2) C#/.NET Five Final Little Wonders (part 3) The C#/.NET Little ......

Posted On Monday, September 26, 2011 3:44 PM | Comments (3) |

C#/.NET Little Wonders: String Padding and Trimming - Not Just for Spaces!
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. This post continues a series of Little Wonders in the BCL String class. Yes, we all work with strings in .NET daily, so perhaps you already know most of these. However, there are a lot of little fun things that the String class can do that often get overlooked. ......

Posted On Thursday, September 22, 2011 6:27 PM | Comments (7) |

C#/.NET Little Wonders: The String Remove() and Replace() 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. This post continues a series of Little Wonders in the BCL String class. Yes, we all work with strings in .NET daily, so perhaps you already know most of these. However, there are a lot of little fun things that the String class can do that often get overlooked. ......

Posted On Thursday, September 15, 2011 6:31 PM | Comments (8) |

C#/.NET Little Wonders: The String Split() and Join() 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. This post continues a series of Little Wonders in the BCL String class. Yes, we all work with strings in .NET daily, so perhaps you already know most of these. However, there are a lot of little fun things that the String class can do that often get overlooked. ......

Posted On Thursday, September 8, 2011 7:21 PM | Comments (20) |

C#/.NET Little Wonders: An Oft Overlooked String Constructor
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. I’m going to begin a series of Little Wonders in the BCL String class. Yes, we all work with strings in .NET daily, so perhaps you already know most of these. However, there are a lot of little fun things that the String class can do that often get overlooked and ......

Posted On Thursday, September 1, 2011 6:45 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) |

C#/.NET Little Wonders: The ReferenceEquals() 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 post can be found here. Today we’re going to look at a very small, and sometimes helpful static method of the object class. Of course, we know most of the key methods of the object class by heart, especially the ones we tend to override often such as Equals(), GetHashCode(), and ToString(). ......

Posted On Thursday, August 18, 2011 7:03 PM | Comments (8) |

C#/.NET Little Wonders & Little Pitfalls: The Complete Collection
I wanted to repost the index of all the Little Wonders and Little Pitfalls posts and presentations so that they would be readily visible for anyone new to these series. I also linked in my C#/.NET Fundamentals presentation "Of Lambdas and Linq", a short primer for those just starting with LINQ and lambda expressions. The Original C#/.NET Little Wonders Trilogy C#/.NET Five Little Wonders (part 1) C#/.NET Five More Little Wonders (part 2) C#/.NET Five Final Little Wonders (part 3) The C#/.NET Little ......

Posted On Thursday, August 11, 2011 6:03 PM | Comments (0) |

C#/.NET Little Wonders and Little Pitfalls at the St. Louis Day of .NET
This Friday and Saturday I will be giving my C#/.NET "Little Wonders" and "Little Pitfalls" presentations to the St. Louis Day of .NET Conference in St. Louis, Missouri at the Ameristar Casino and Conference Center. I'm including the presentations here for the attendees and anyone else interested. The C#/.NET Little Wonders presentation has been touched up a bit. C#/.NET Little Wonders View more presentations from BlackRabbitCoder The C#/.NET Little Pitfalls presentation is brand new, let me know ......

Posted On Thursday, August 4, 2011 10:07 PM | Comments (5) |

C#/.NET Little Pitfalls: Default Parameters are Compile-Time Substitutions
C# is a wonderful language for modern programming. While everything in C# has a reason and a place, occasionally there are things that can be confusing for a developer who isn’t aware of what is happening behind the scenes. This is my fifth post in the Little Pitfalls series where I explore these issues; the previous Little Pitfall post can be found here. Side Note: I’ll be presenting sessions on the Little Wonders and the Little Pitfalls at the St. Louis Day of .NET conference on August 5th and ......

Posted On Thursday, July 28, 2011 6:24 PM | Comments (5) |

C#/.NET Little Pitfalls: Nullable Math Doesn't Always Add Up
C# is a wonderful language for modern programming. While everything in C# has a reason and a place, occasionally, there are things that can be confusing for a developer who isn’t aware of what is happening behind the scenes. This is my third post in the Little Pitfalls series where I explore these small pitfalls; the previous Little Pitfall post can be found here. In the last Little Wonders post, we talked about the Nullable static class (not to be confused with the Nullable<T> struct) and ......

Posted On Thursday, July 14, 2011 7:54 PM | Comments (6) |

C#/.NET Little Wonders: The Nullable static class
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 we’re going to look at an interesting Little Wonder that can be used to mitigate what could be considered a Little Pitfall. The Little Wonder we’ll be examining is the System.Nullable static class. No, not the System.Nullable<T> class, but a static ......

Posted On Thursday, June 30, 2011 6:52 PM | Comments (4) |

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 Fundamentals: Choosing the Right Collection Class
The .NET Base Class Library (BCL) has a wide array of collection classes at your disposal which make it easy to manage collections of objects. While it's great to have so many classes available, it can be daunting to choose the right collection to use for any given situation. As hard as it may be, choosing the right collection can be absolutely key to the performance and maintainability of your application! This post will look at breaking down any confusion between each collection and the situations ......

Posted On Thursday, June 16, 2011 7:11 PM | Comments (55) |

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 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 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: Tuples and Tuple Factory 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. This week, we look at the System.Tuple class and the handy factory methods for creating a Tuple by inferring the types. What is a Tuple? The System.Tuple is a class that tends to inspire a reaction in one of two ways: love or hate. Simply put, a Tuple is a data structure that holds a specific number of items of a specific ......

Posted On Thursday, March 10, 2011 6:37 PM | Comments (12) |

C#/.NET Little Wonders: ConcurrentBag and BlockingCollection
In the first week of concurrent collections, began with a general introduction and discussed the ConcurrentStack<T> and ConcurrentQueue<T>. The last post discussed the ConcurrentDictionary<T> . Finally this week, we shall close with a discussion of the ConcurrentBag<T> and BlockingCollection<T>. For more of the "Little Wonders" posts, see C#/.NET Little Wonders: A Redux. Recap As you'll recall from the previous posts, the original collections were object-based containers ......

Posted On Thursday, March 3, 2011 6:56 PM | Comments (9) |

C#/.NET Little Wonders & Little Pitfalls: The Complete Collection
I wanted to repost the index of all the Little Wonders and Little Pitfalls posts and presentations so that they would be readily visible for anyone new to these series. I also linked in my C#/.NET Fundamentals presentation "Of Lambdas and Linq", a short primer for those just starting with LINQ and lambda expressions. The Original C#/.NET Little Wonders Trilogy C#/.NET Five Little Wonders (part 1) C#/.NET Five More Little Wonders (part 2) C#/.NET Five Final Little Wonders (part 3) The C#/.NET Little ......

Posted On Tuesday, February 22, 2011 9:17 PM | Comments (1) |

C#/.NET Little Wonders: The ConcurrentDictionary
Once again we consider some of the lesser known classes and keywords of C#. In this series of posts, we will discuss how the concurrent collections have been developed to help alleviate these multi-threading concerns. Last week’s post began with a general introduction and discussed the ConcurrentStack<T> and ConcurrentQueue<T>. Today's post discusses the ConcurrentDictionary<T> (originally I had intended to discuss ConcurrentBag this week as well, but ConcurrentDictionary had enough ......

Posted On Thursday, February 17, 2011 6:00 PM | Comments (17) |

C#/.NET Little Wonders: The ConcurrentStack and ConcurrentQueue
Once again we consider some of the lesser known classes and keywords of C#. In the next few weeks, we will discuss the concurrent collections and how they have changed the face of concurrent programming. This week’s post will begin with a general introduction and discuss the ConcurrentStack<T> and ConcurrentQueue<T>. Then in the following post we’ll discuss the ConcurrentDictionary<T> and ConcurrentBag<T>. Finally, we shall close on the third post with a discussion of the ......

Posted On Thursday, February 10, 2011 7:30 PM | Comments (3) |

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 Little Pitfalls: The Dangers of Casting Boxed Values
Starting a new series to parallel the Little Wonders series. In this series, I will examine some of the small pitfalls that can occasionally trip up developers. Introduction: Of Casts and Conversions What happens when we try to assign from an int and a double and vice-versa? 1: double pi = 3.14; 2: int theAnswer = 42; 3: 4: // implicit widening conversion, compiles! 5: double doubleAnswer = theAnswer; 6: 7: // implicit narrowing conversion, compiler error! 8: int intPi = pi; As you can see from the ......

Posted On Thursday, January 27, 2011 7:30 PM | Comments (1) |

C#/.NET Little Wonders: Comparer<T>.Default
I’ve been working with a wonderful team on a major release where I work, which has had the side-effect of occupying most of my spare time preparing, testing, and monitoring. However, I do have this Little Wonder tidbit to offer today. Introduction The IComparable<T> interface is great for implementing a natural order for a data type. It’s a very simple interface with a single method Compare() that compares two items of type T and returns an integer result. So what do we expect for the integer ......

Posted On Thursday, January 20, 2011 9:08 PM | Comments (5) |

C#/.NET Little Wonders: Constraining Generics with Where Clause
Back when I was primarily a C++ developer, I loved C++ templates. The power of writing very reusable generic classes brought the art of programming to a brand new level. Unfortunately, when .NET 1.0 came about, they didn’t have a template equivalent. With .NET 2.0 however, we finally got generics, which once again let us spread our wings and program more generically in the world of .NET However, C# generics behave in some ways very differently from their C++ template cousins. There is a handy clause, ......

Posted On Thursday, January 13, 2011 6:29 PM | Comments (0) |

C#/.NET Little Wonders: Cross Calling Constructors
Just a small post today, it’s the final iteration before our release and things are crazy here! This is another little tidbit that I love using, and it should be fairly common knowledge, yet I’ve noticed many times that less experienced developers tend to have redundant constructor code when they overload their constructors. The Problem – repetitive code is less maintainable Let’s say you were designing a messaging system, and so you want to create a class to represent the properties for a Receiver, ......

Posted On Thursday, December 16, 2010 6:24 PM | Comments (3) |

C#/.NET Little Wonders: Fun With Enum Methods
Once again lets dive into the Little Wonders of .NET, those small things in the .NET languages and BCL classes that make development easier by increasing readability, maintainability, and/or performance. So probably every one of us has used an enumerated type at one time or another in a C# program. The enumerated types we create are a great way to represent that a value can be one of a set of discrete values (or a combination of those values in the case of bit flags). But the power of enum types ......

Posted On Thursday, December 9, 2010 5:50 PM | Comments (5) |

C#/.NET Little Wonders: DateTime is Packed with Goodies
Once again lets dive into the Little Wonders of .NET, those small things in the .NET languages and BCL classes that make development easier by increasing readability, maintainability, or performance. Today I’m going to focus a bit on the System.DateTime. This nice little value type (struct) has been in the BCL since the beginning, and while being broadly used to represent an instance of a date and time, there are many great properties, methods, and operators in this class that perhaps folks are less ......

Posted On Thursday, November 18, 2010 6:45 PM | Comments (8) |

C#/.NET Little Wonders & Little Pitfalls: The Complete Collection
I wanted to repost the index of all the Little Wonders and Little Pitfalls posts and presentations so that they would be readily visible for anyone new to these series. I also linked in my C#/.NET Fundamentals presentation "Of Lambdas and Linq", a short primer for those just starting with LINQ and lambda expressions. The Original C#/.NET Little Wonders Trilogy C#/.NET Five Little Wonders (part 1) C#/.NET Five More Little Wonders (part 2) C#/.NET Five Final Little Wonders (part 3) The C#/.NET Little ......

Posted On Thursday, November 11, 2010 7:05 PM | Comments (8) |

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 (29) |

C# Fundamentals – Two Things That Only Initializers Can Easily Do…
Thanks a lot, everyone, for all your comments and feedback on my Five Little Wonders Trilogy of posts. This week, it’s crunch time at my workplace so this post is going to be on the brief side. As I’ve been coding on my latest project, it struck me that there’s at least two things that object/collection initializers can do that you can’t easily do without them. Refresher on Initializers For those of you who don’t know or can’t remember, object initializers are when you assign members of a class or ......

Posted On Thursday, September 16, 2010 7:44 PM | Comments (4) |

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#/.NET Five More Little Wonders That Make Code Better (2 of 3)
So last week I began my series with a post (here) on those little wonders in .NET/C# -- those small tips and tricks that make code either more concise, maintainable, or performant. This is the second of my three-part series, though there are so many things that make .NET (and in particular C#) a great development platform that I'm sure I could carry this blog on ad infinitum. Once again, many of these are ones you may already know, but hopefully some of you will find something new or be reminded ......

Posted On Thursday, September 2, 2010 6:20 PM | Comments (30) |

C#/.NET Five Little Wonders That Make Code Better (1 of 3)
We all have those little wonders in our .NET code, those small tips and tricks that make code just that much more concise, maintainable, or performant. Many of you probably already know of some of these, but many folks either overlook them or just don't know about them, so this article is a refresher. I'm planning on making this a three-part series encompassing 15 little wonders that I had thought of, though I'm very curious to hear the little wonders you can think of as well. Update: Part 2 is now ......

Posted On Thursday, August 26, 2010 6:32 PM | Comments (63) |

C#: System.Lazy<T> and the Singleton Design Pattern
So we've all coded a Singleton at one time or another. It's a really simple pattern and can be a slightly more elegant alternative to global variables. Make no mistake, Singletons can be abused and are often over-used -- but occasionally you find a Singleton is the most elegant solution. For those of you not familiar with a Singleton, the basic Design Pattern is that a Singleton class is one where there is only ever one instance of the class created. This means that constructors must be private to ......

Posted On Wednesday, May 19, 2010 6:41 PM | Comments (33) |

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) |

Powered by: