C# Extension Methods, Part 3

While I’ll probably (have to) focus on Java for the next month, I just came up with the idea of just another extension method class. It is acually not very helpful but it again shows how powerful extension methods can be.

This is how it can be used:

StringBuilder buffer = new StringBuilder();
foreach (int i in 10.To(15))
{
    buffer.AppendLine("" + i);
}

I know that this piece of code does not look very helpful, because the same can easily be done using a simple for loop, but there might be some cases – especially when using LINQ – when it is quite useful to have an iterable range of int values.

The code is up on my github C# extension method project. Feel free to use or fork it.

Comments are closed.