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

.NET

There are 119 entries for the tag .NET
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) |

Review: A Quick Look at Reflector
I, like many, was disappointed when I heard that Reflector 7 was not free, and perhaps that’s why I waited so long to try it and just kept using my version 6 (which continues to be free). But though I resisted for so long, I longed for the better features that were being developed, and began to wonder if I should upgrade. Thus, I began to look into the features being offered in Reflector 7.5 to see what was new. Multiple Editions Reflector 7.5 comes in three flavors, each building on the features ......

Posted On Thursday, June 21, 2012 4:50 PM | Comments (4) |

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#/.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 Fundamentals: Unit Testing with Func<TResult> Generators
The C#/.NET Fundamentals series is geared towards examining fundamental concepts in using C# (and .NET in general) to produce effective solutions. I wanted to attempt a brief post before the holidays, so I decided to quickly revisit part a post I wrote a few weeks back on The Generic Func Delegates, and in particular, the sidebar on using Func as a generator for unit testing. At the time, I did not give that short sidebar the attention I really wanted, including showing the setup of the unit tests ......

Posted On Thursday, December 22, 2011 5:33 PM | Comments (12) |

C#/.NET Fundamentals: Returning Zero or One Item As IEnumerable<T>
The C#/.NET Fundamentals series is geared towards examining fundamental concepts in using C# (and .NET in general) to produce effective solutions. There are times when we are writing a method that returns a sequence of items, that it occasionally becomes necessary in base-class, interface implementation, error, or default conditions to return a sequence of only one or even zero items. There are many ways to do this, of course, which begs the question of which way is best, in terms of readability, ......

Posted On Thursday, December 8, 2011 6:32 PM | Comments (9) |

C#/.NET Fundamentals: Safely and Efficiently Raising Events
The C#/.NET Fundamentals series is geared towards examining fundamental concepts in using C# (and .NET in general) to produce effective solutions. A couple of posts ago, I discussed the EventHandler<TEventArgs> and EventHandler delegates, and in particular at one point mentioned in a sidebar that you need to watch out for thread-safety in order to safely raise events in a multi-threaded environment. There was an interesting discussion in the comments about different ways that people achieve ......

Posted On Thursday, December 1, 2011 8:10 PM | Comments (15) |

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

Review – InRule: A Business Rules Management System for .NET
I don’t usually do a product profile unless I either really like the product and use it myself, or I’m genuinely curious about the product and what it can do for me. While I haven’t used InRule before, it does fit the latter of those criteria because of my interest in similar products I have used in the past. A Quick Intro to my Life in Rules… Flash back to my college years (when 5.25” floppies were king) and you’d see a young guy in an Artificial Intelligence class learning about a Knowledge Based ......

Posted On Wednesday, November 2, 2011 8:10 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, 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 Toolbox: Creating a "Safer" Task Dispose()
This post is another in a series that contains generic utility classes I’ve developed along the way to help make coding a bit easier. 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!). Update: modified the TryDispose() method to check for IsCompleted first and mark any Task exceptions as handled. So recently, I’ve been moving some older ......

Posted On Thursday, October 6, 2011 7:41 PM | Comments (2) |

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

ANTS Performance Profiler
I’ve always liked Red Gate products. Reflector is a great tool for decompiling assemblies to see how something was constructed, and the ANTS Memory Profiler is an excellent tool for discovering sources of memory issues in your applications. So when I had a chance to really examine the latest ANTS Performance Profiler (6.3), I jumped at the opportunity to see how well it works. Background A performance profiler’s main job is to keep track of how much time is typically spent in each unit of code. This ......

Posted On Thursday, September 8, 2011 9:24 AM | Comments (5) |

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: The Default is to Hide, Not Override
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 fourth post in the Little Pitfalls series where I explore these issues; the previous Little Pitfall post can be found here. Today we are going to look at a potential pitfall that can bite developers who expect the default behavior of declaring the same method (with ......

Posted On Thursday, July 21, 2011 6:10 PM | Comments (6) |

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

Visual C# MVP, 2011
I was informed on July 1st, 2011 that I was awarded a Microsoft Visual C# MVP recognition for 2011. I'm very thankful to have been nominated and selected, and thankful that you guys all find my posts informative and useful! I'll try my best to keep up the good work! Thanks to everyone! Tweet Technorati Tags: .NET, C#, MVP ......

Posted On Wednesday, July 13, 2011 8:06 PM | Comments (9) |

C#/.NET Little Pitfalls: Operators are Overloaded, not Overridden
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. This week we’re going to look at operator overloading. Yes, I bolded that because it is very important to note we overload operators, ......

Posted On Thursday, July 7, 2011 7:11 PM | Comments (5) |

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

Automating C# Coding Standards Using FxCop and StyleCop
Re-posting my presentation on Automating Code Standards that I'm presenting to the Cedar Rapids (Iowa) .NET Users Group - CRINETA - tonight. For more details see their web site at: crineta.org The presentation can be found on Slideshare at http://www.slideshare.net/B... Automating C# Coding Standards using StyleCop and FxCop View more presentations from BlackRabbitCoder Tweet Technorati Tags: C#, .NET, StyleCop, FxCop ......

Posted On Monday, June 6, 2011 3:53 PM | Comments (0) |

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

Tech Ed 2011 Atlanta – It’s Good to Be an Alumni
Woke up this morning and decided to finally stop by the Alumni Lounge. I had been meaning to check it out, but I had been so busy with such great presentations and hanging out in the Blogger’s Lounge that I never got around to it. I truly wish I had stopped in sooner! There’s nice bottles of soda with glasses for ice so you can have it nice and cold as well as a hot beverage bar. And this morning there were delicious cinnamon rolls (the nemesis of my beltline, alas!) and other treats and candies. ......

Posted On Wednesday, May 18, 2011 10:26 AM | Comments (1) |

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

Automating C# Coding Standards Using FxCop and StyleCop
Just uploaded my presentation to the Springfield (Missouri) Dot Net Users' Group to Slideshare at http://www.slideshare.net/B... Automating C# Coding Standards using StyleCop and FxCop View more presentations from BlackRabbitCoder Tweet Technorati Tags: C#, .NET, StyleCop, FxCop ......

Posted On Wednesday, April 27, 2011 10:18 PM | Comments (2) |

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

ANTS Memory Profiler 7.0
I had always been a fan of ANTS products (Reflector is absolutely invaluable, and their performance profiler is great as well – very easy to use!), so I was curious to see what the ANTS Memory Profiler could show me. You can check out more information about the profiler at Red Gate's web site at www.red-gate.com/products/d... Background While a performance profiler will track how much time is typically spent in each unit of code, a memory profiler gives you much ......

Posted On Thursday, March 10, 2011 2:55 PM | Comments (0) |

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 Toolbox: A Debugable, Self-Installable Windows Service Template (Redux)
The Original Posts I had written a pair of posts before about creating a debug-able and self-installing windows service template in C#. This is a template I began creating to ease creating windows services and to take some of the mundane tasks out of the coding effort. The original posts were here: C# Windows Services (1 of 2) - Debug-able Windows Services C# Windows Services (2 of 2) - Self-Installing Windows Services But at the time, though I gave the code samples I didn't have a downloadable for ......

Posted On Tuesday, March 1, 2011 1:08 AM | Comments (5) |

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 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 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 Toolbox: Generic Reversing Comparers
I’m going to start another series of posts that I’m calling C#/.NET Toolbox 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!). Update: improved the ReverseComparer and added an extension method that will reverse any comparer instance. The Problem: ......

Posted On Thursday, December 2, 2010 7:37 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 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 Fundamentals: Returning Data Immutably in a Mutable World
One of the things I sort-of miss from C++ (it has its good and bad) is the const modifier. Yes, while it’s true that we have a const modifier in C# (as well as readonly), but it’s not quite as robust. Many times you’ll want to return an internal member of a class but not want it to be directly modifiable by the user of that class. This article discusses how to present simple types as read-only. Note: I’m deliberately avoiding creating read-only views of collections in this particular article, but ......

Posted On Thursday, October 28, 2010 6:21 PM | Comments (4) |

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# 5.0 And Beyond: Upper/Lower Case Format Specifiers
So, I thought of another thing I’d like in my wish list of features I’d love to see in C# 5.0 and beyond. I’d like a format specifier to put the upper or lower case converted format argument into a formatted string. That is, let’s say you are building a distributed cache key that takes as part of the key the host name, but sometimes you may get the same host name in upper, lower, or mixed case on your distributed cache provider is case sensitive in its comparison and you have no control over that. ......

Posted On Monday, October 11, 2010 2:08 PM | Comments (7) |

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

C# 5.0 and Beyond - My Wish List
I apologize in advance to those waiting for part 2 of the Windows Services post I did last week. I will have a follow-up post next week, this week at work has just been crazy and I haven’t had as much time to devote to the code examples as I’d like to polish it. So instead I thought I’d throw a quick post out on what I’d like to see in the future versions of C#. A lot of folks are posting things they would like to see in C# 5.0 and beyond. There’s a great list on Stack Overflow (here) and a great ......

Posted On Friday, October 1, 2010 10:15 AM | Comments (8) |

C# Toolbox: A Debuggable, Self-Installing Windows Service Template (1 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. I decided to write a pair of posts on making it easier to create Windows Services in C# (and in .NET in general). This is the first post that talks about how to make a Windows Service debuggable (the default visual studio template does not allow the service to be easily debugged), and then next week’s post will discuss making the Windows Service self-installing. Now, these posts ......

Posted On Thursday, September 23, 2010 5:59 PM | Comments (6) |

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

10 Things C++ Developers Learning C# Should Know
After taking a lot of time with C# fundamentals, I decided to go down a different road this week and talk about some of the differences in C# that can be troublesome to people who are used to C++ development but are learning C#. My first post on this blog months ago was just a simple piece on how I divorced C++ as my first-love language (here). This is not to say that C++ is not still a valuable language, in fact as far as object-oriented languages go C++ is still king of performance. That said, ......

Posted On Thursday, August 12, 2010 5:34 PM | Comments (4) |

C# Fundamentals: Parameters Passing Nuances
Last week I went into quite a bit of detail on C# struct (here) and the consequences of using a struct versus a class to represent complex data types. In the course of that article, I had a section describing the differences between value types and reference types and thought I would expand upon one of the ideas in there which seems to confuse some folks who are new to C#: parameter passing nuances. But first, let's lay the groundwork with some definitions: Parameter - the variable defined in a method ......

Posted On Thursday, August 5, 2010 6:18 PM | Comments (1) |

C# Fundamentals: The Differences Between Struct and Class
This week in C# Fundamentals, we'll tackle the basic differences between C# struct and class types. Sure, this has been discussed many times by many different people, but I believe it's one of those subjects that needs to be brought up over and over again to help people new to the language and refresh people who may have forgotten all the minutia. Introduction: So, what is the difference between a struct and a class? Well, if you have only ever been exposed to the Java world, there is no concept ......

Posted On Thursday, July 29, 2010 8:57 PM | Comments (13) |

C# Fundamentals: Combining Enum Values with Bit-Flags
Two posts ago, I talked about the C# enum and some of its pitfalls (here). This post continues with a discussion of the fundamentals of enums by continuing with using enums and bit-flags. Defining a [Flags] Enum Now, we’ve seen previously that enums are typically used when you want to represent a type that can be one of a distinct set of values. But they can also be used to store a combination of discrete values. That is, the standard use of an enumeration is to support mutex options - such as an ......

Posted On Thursday, July 22, 2010 5:46 PM | Comments (10) |

C# Toolbox: Building a Loosely Coupled Translator
In my last fundamentals post, Chuck had requested an example of how to translate between enum and int without resorting to casting or other hard-coded mechanisms that depend on the actual values of the enum. One of the problems, of course, with casting between enum and int (for example to represent the enum as an int in database) is that it is a very tightly-coupled bond. Any changes to the underlying data or to the enum could have disastrous consequences. Thus, it is often more desirable to have ......

Posted On Tuesday, July 13, 2010 11:10 PM | Comments (2) |

C# Fundamentals: The Joys and Pitfalls of Enums
Continuing on the same vein as my last topic where I discussed differences between C# const and readonly keywords (here) and their uses, today I’m going to look at C# enums and their pitfalls. I will only be discussing the basic enums today (the post got kind of long so I’ll discuss enums marked with the [Flags] attribute next post). Quick Recap of Enums First, a quick recap of enums for those who are brand new or less familiar with them. Basically, enums a great way to declare a variable of a type ......

Posted On Thursday, July 8, 2010 5:53 PM | Comments (5) |

C# Fundamentals - What is the Difference Between Const and Readonly?
Once again we delve into the world of C# Fundamentals. Those hints and gotchas that tend to bite folks newer to the language. Today I take another look about the differences between const and readonly and the uses for each. For the purposes of this entry, whenever I say constant i mean a const or readonly. Const – Compile-Time Constant Values First of all, for those of you who came from the C++ and C# world, const in C# is not the same as const in that language. A const in C# can be closest considered ......

Posted On Thursday, July 1, 2010 5:28 PM | Comments (8) |

C# Fundamentals: Beware Of Implicit Hiding
C# Fundamentals Genesis I’ve decided to begin a line of back-to-basics blogs that I hope to post regularly. I used to teach C++ Programming, Algorithms, and Data Structures courses at Webster University in the evenings here locally, and have missed those teaching and mentoring moments when I had to stop teaching after the birth of my twins (no more free time for me!). While some of these fundamentals will be obvious to those who know the languages well (I hope to post C# and C++ tidbits), I’m hoping ......

Posted On Thursday, June 24, 2010 6:11 PM | Comments (4) |

C# Fundamentals: Optional Parameters - Pros and Pitfalls
When Microsoft rolled out Visual Studio 2010 with C# 4, I was very excited to learn how I could apply all the new features and enhancements to help make me and my team more productive developers. Default parameters have been around forever in C++, and were intentionally omitted in Java in favor of using overloading to satisfy that need as it was though that having too many default parameters could introduce code safety issues. To some extent I can understand that move, as I’ve been bitten by default ......

Posted On Thursday, June 17, 2010 6:11 PM | Comments (5) |

Premature-Optimization and Performance Anxiety
While writing my post analyzing the new .NET 4 ConcurrentDictionary class (here), I fell into one of the classic blunders that I myself always love to warn about. After analyzing the differences of time between a Dictionary with locking versus the new ConcurrentDictionary class, I noted that the ConcurrentDictionary was faster with read-heavy multi-threaded operations. Then, I made the classic blunder of thinking that because the original Dictionary with locking was faster for those write-heavy uses, ......

Posted On Sunday, June 13, 2010 8:42 PM | Comments (1) |

C#: The Curious ConcurrentDictionary
Update: I revised some of my initial thoughts after taking bit of my own advice and thinking about the less-tangible benefits of a ConcurrentDictionary. This leads me to believe that ay time you use a Dictionary in a read/write manner in a multi-threaded environment, you should use ConcurrentDictionary instead for the simplicity and safety. It's easier to read and more maintainable, and even if you are write-heavy, it's not orders-of-magnitude slower so I think it's worth it for the safety and maintainability ......

Posted On Wednesday, June 9, 2010 5:45 PM | Comments (22) |

C#: System.Collections.Concurrent.ConcurrentQueue vs. Queue
I love new toys, so of course when .NET 4.0 came out I felt like the proverbial kid in the candy store! Now, some people get all excited about the IDE and it’s new features or about changes to WPF and Silver Light and yes, those are all very fine and grand. But me, I get all excited about things that tend to affect my life on the backside of development. That’s why when I heard there were going to be concurrent container implementations in the latest version of .NET I was salivating like Pavlov’s ......

Posted On Monday, June 7, 2010 8:37 PM | Comments (9) |

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#: Handling Notifications: inheritance, events, or delegates?
Often times as developers we have to design a class where we get notification when certain things happen. In older object-oriented code this would often be implemented by overriding methods -- with events, delegates, and interfaces, however, we have far more elegant options. So, when should you use each of these methods and what are their strengths and weaknesses? Now, for the purposes of this article when I say notification, I'm just talking about ways for a class to let a user know that something ......

Posted On Tuesday, May 18, 2010 6:10 PM | Comments (5) |

C# Fundamentals: String Concat() vs. Format() vs. StringBuilder
I was looking through my groups’ C# coding standards the other day and there were a couple of legacy items in there that caught my eye. They had been passed down from committee to committee so many times that no one even thought to second guess and try them for a long time. It’s yet another example of how micro-optimizations can often get the best of us and cause us to write code that is not as maintainable as it could be for the sake of squeezing an extra ounce of performance out of our software. ......

Posted On Monday, May 10, 2010 9:59 PM | Comments (6) |

C#: Does an IDisposable in a Halted Iterator Dispose?
If that sounds confusing, let me give you an example. Let's say you expose a method to read a database of products, and instead of returning a List<Product> you return an IEnumerable<Product> in iterator form (yield return). This accomplishes several good things: The IDataReader is not passed out of the Data Access Layer which prevents abstraction leak and resource leak potentials. You don't need to construct a full List<Product> in memory (which could be very big) if you just want ......

Posted On Tuesday, May 4, 2010 7:52 PM | Comments (2) |

C#: Adding Functionality to 3rd Party Libraries With Extension Methods
Ever have one of those third party libraries that you love but it's missing that one feature or one piece of syntactical candy that would make it so much more useful? This, I truly think, is one of the best uses of extension methods. I began discussing extension methods in my last post (which you find here) where I expounded upon what I thought were some rules of thumb for using extension methods correctly. As long as you keep in line with those (or similar) rules, they can often be useful for adding ......

Posted On Wednesday, April 28, 2010 10:58 PM | Comments (1) |

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

Powered by: