AsSequenceTo

using System;
using System.Collections.Generic;
using System.Linq;

namespace IntegerExtensions
{
    /// <summary>
    /// Contains extension methods for Lists of integers
    /// </summary>
    public static class IntegerExtensions
    {

        /// <summary>
        /// Creates a numeric list of integers starting at the current instance and ending 
        /// at the maximum value.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="maxValue">The initial value.</param>
        /// <returns></returns>
        public static List<int> AsSequenceTo(this int instance, int maxValue)
        {
            // Validate arguments
            if (maxValue < instance) throw new ArgumentOutOfRangeException("maxValue", maxValue, "maxValue must not be less than the instance. ");

            int count = (maxValue - instance + 1);
            return Enumerable.Range(instance, count).ToList();
        }
    }
}
Example:
        [TestMethod]
        public void AsSequenceTo_EndsAtMximumValue()
        {
            // ARRANGE
            const int initialValue = 3;
            const int maximumValue = 5;
            const int expectedEnd = maximumValue;

            // ACT
            var result = initialValue.AsSequenceTo(maximumValue);
            var actual = result.Last();

            // ASSERT
            Assert.AreEqual(expectedEnd, actual);
        }

Description

Creates a numeric list of integers starting at the current instance and ending at the maximum value.

Details

Double click on the code to select all.

 

;