How to insert new item into an IEnumerable

Viewed 35994

I create a dropdownlist from Enum.

public enum Level
{
    Beginner = 1,
    Intermediate = 2,
    Expert = 3
}

here's my extension.

    public static SelectList ToSelectList<TEnum>(this TEnum enumObj)
    {

        IEnumerable<TEnum> values = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();

        var result = from TEnum e in values
                     select new { ID = (int)Enum.Parse(typeof(TEnum), e.ToString()), Name = e.ToString() };

        var tempValue = new { ID = 0, Name = "-- Select --" };


        return new SelectList(result, "Id", "Name", enumObj);
    }

the problem I have is to insert antoher item into IEnumerable. I just could not figure out how to do it. Can someone please modify my code to insert "--select--" to the top.

3 Answers
Related