BlackRabbitCoder

Stories submitted by BlackRabbitCoder

C#/.NET Little Wonders: Select() and Where() with Indexes(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 9 days, 3 hours ago

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 methods in their simplest form, where they simply take a projection and predicate respectively that operates on just an element. However, there are overloads for both of these methods that take a delegate that operates on both the element and the index of the element. read more...

1 comment |category: |Views: 282

tags: another

C#/.NET Little Wonders: The Enumerable.Repeat() Static Method(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 23 days, 3 hours ago

The Enumerable.Repeat() method performs the simple task of creating a sequence by repeating an element a specific number of times. While this is, in of itself, a trivial need, it can also be used to drive more useful results such as repeating a generator delegate, or creating sequences out of single items. read more...

1 comment |category: |Views: 295

tags: another

C#/.NET Little Wonders: The Enumerable.Range() Static Method(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 1 month ago

The Enumerable.Range() method performs a very simple function, but it’s results can be used to drive much more complex LINQ expressions. Feel free to use it for generating simple int sequences all the way to generating sequences of a repeated action. Either way, it’s a good tool to keep handy. read more...

1 comment |category: |Views: 10

tags: another

C#/.NET Little Wonders: Skip() and Take()(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 1 month, 27 days ago

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 simple, they are an easy way to create sub-sequences for IEnumerable<T>, much the way GetRange() creates sub-lists for List<T>. read more...

1 comment |category: |Views: 39

tags: another

C++ Little Wonders: The C++11 auto keyword redux(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 2 months, 11 days ago

Today I’m going to focus on a new feature in C++11 (formerly known as C++0x, which is a major move forward in the C++ language standard). While this small keyword can seem so trivial, I feel it is a big step forward in improving readability in C++ programs. read more...

1 comment |category: |Views: 87

tags: another

C#/.NET Little Wonders – The DateTimeOffset struct(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 2 months, 18 days ago

While the DateTime is a powerful structure for parsing, manipulating, and comparing date-times, it becomes problematic when handling times from different time-zones. The DateTimeOffset is much more portable in that it preserves the offset from UTC. read more...

2 comments |category: |Views: 163

tags: another

C#/.NET Little Wonders–The List<T> Range Methods(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 3 months, 3 days ago

While LINQ gives a lot of power to query IEnumerable<T> sequences in general, many of the collections themselves have specialized methods that allow manipulation and efficient queries. In particular, the List<T> class contains four methods to query and manipulate ranges of items: AddRange(), InsertRange(), RemoveRange(), and GetRange(). read more...

1 comment |category: |Views: 266

tags: another

C#/.NET Little Wonders: The SequenceEqual() Method(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 3 months, 10 days ago

This post examines a handy method of the Enumerable class that allows you to check if two sequences of values are equal. Equality of two sequences is defined as two sequences of the same length with equivalent values in the same order from both sequences. read more...

1 comment |category: |Views: 3

tags: another

C#/.NET Little Pitfalls: Implicit Zero To Enum Conversion(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 4 months ago

Many times, we create overloaded methods or constructors to allow them to accept different kinds of data. Further, there are times that we may accept object when any value will do. This works well (aside from boxing/unboxing concerns for value types), but if you have an overload that accepts object and one that takes an enum, and you pass a constant expression of 0, where does it go? read more...

3 comments |category: |Views: 212

tags: another

C#/.NET Little Pitfalls: Stopwatch Ticks are not TimeSpan Ticks(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 4 months, 14 days ago

The System.Diagnostics.Stopwatch class is very useful for elapsed time measurements in .NET applications. Today we’ll look at the ElapsedTicks member of the Stopwatch class, and some of the confusion of what this quantity represents, especially compared to TimeSpan or DateTime Ticks. read more...

1 comment |category: |Views: 3

tags: another

C#/.NET Little Wonders: The DateTime TryParsae() and ParseExact() Meth(blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 4 months, 21 days ago

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 a DateTime. Most of us have dealt with using DateTime.Parse() for these tasks, but sometimes you are wanting to parse something that may not be a valid DateTime, or may be in a non-standard format. So let’s look at the TryParse() and ParseExact() methods that can be used to deal with these two situations. read more...

1 comment |category: |Views: 7

tags: another

C#/.NET Fundamentals: Unit Testing with Func<TResult> Generators(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 5 months, 4 days ago

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 and discussing the performance impact (if any) of such a practice. So this week I hope to rectify this by revisiting and enhancing the discussion. read more...

1 comment |category: |Views: 13

tags: another

C# Fundamentals: Returning Zero or One Item As IEnumerable<T>(blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 5 months, 18 days ago

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, maintainability, and performance. read more...

2 comments |category: |Views: 40

tags: another

C#/.NET Fundamentals: Safely and Efficiently Raising Events(www.blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 5 months, 25 days ago

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 their thread-safety when raising events, and that got me interested in exploring them more in detail and checking them for performance. This post examines several ways to raise events in a thread-safe manner, and compares the performance aspects of each. read more...

1 comment |category: |Views: 30

tags: another

C#/.NET Little Wonders: The Predicate, Comparison, and Converter Gener(blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 6 months, 2 days ago

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 be completing my series on the generic delegates in the .NET Framework with a discussion of three more, somewhat less used, generic delegates: Predicate<T>, Comparison<T>, and Converter<TInput, TOutput>. These are older generic delegates that were introduced in .NET 2.0, mostly for use in the Array and List<T> classes. Though older, it’s good to have an understanding of them and their intended purpose. In addition, you can feel free to use them yourself, though obviously you can also use the equivalents from the Func family of delegates instead. read more...

1 comment |category: |Views: 56

tags: another

C#/.NET Little Wonders: The EventHandler and EventHandler<TEventArgs> (blackrabbitcoder.net)

submitted by BlackRabbitCoderBlackRabbitCoder(661) 6 months, 9 days ago

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. 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 that can be used to eliminate the need for defining custom delegates when creating events: the EventHandler and EventHandler<TEventArgs> delegates. read more...

2 comments |category: |Views: 25

tags: another