James Michael Hare

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

CSharp

There are 72 entries for the tag CSharp
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#/.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 (7) |

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

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

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

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

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

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

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

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

Powered by: