Well, you could do something like:
List<char> chars = new List<char>();
chars.AddRange(Enumerable.Range(0x0000, 9).Select(i => (char)i));
chars.AddRange(Enumerable.Range(0x000B, 2).Select(i => (char)i));
Not sure it is worth it, though - especially given the need to use "count" rather than "end". Probably easier to write your own extension method...
static void AddRange(this IList<char> list, char start, char end) {
for (char c = start; c <= end; c++) {
list.Add(c);
}
}
static void Main() {
List<char> chars = new List<char>();
chars.AddRange('\u0000', '\u0008');
chars.AddRange('\u000B', '\u000C');
}
Re your comment; extension methods aren't a .NET 3.5 feature. They are a C# 3.0 feature. So as long as you compile the code set to target .NET 2.0 / 3.0 (as appropriate), it doesn't matter if the client doesn't have .NET 3.5; you do, however, need to defined the ExtensionAttribute
- a few lines of code only:
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly |
AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
Or just go for broke and download LINQBridge and use all of LINQ-to-Objects in .NET 2.0.