.NET 3.5 Sequence Methods Moved to Enumerable

I still see a lot of C# code samples around online that use Sequence.Range to generate a numerical range and Sequence.Repeat to repeat a number. This is a little confusing, because these methods may have been around in the early days of .NET 3.0, but have since moved to System.Linq.Enumerable.

Shown below is today’s correct usage for Range and Repeat.

using System.Linq;

// Generate a range of integers
// This will enumerate 3, 4, 5, 6, 7, 8, 9
IEnumerable<int> nums = Enumerable.Range(3, 7);

// Repeat any value a given number of times
// This will enumerate 5, 5, 5
IEnumerable<int> fives = Enumerable.Repeat(5, 3);
// This will enumerate "string", "string"
IEnumerable<string> strings = Enumerable.Repeat("string", 2);

Posted on February 21, 2009 from Calgary

About

My name is Brandur. I'm a polyglot software engineer and part-time designer working at Heroku in San Francisco, California. I'm a Canadian expat. My name is Icelandic. Drop me a line at brandur@mutelight.org.

Aside from technology, I'm interested in energy and how it relates to our society, travel, longboarding, muay thai, symphonic metal, and the guitar.

If you liked this article, consider finding me on Twitter.