Is there a statement to prepend an element T to a IEnumerable<T>
问题 For example: string element = 'a'; IEnumerable<string> list = new List<string>{ 'b', 'c', 'd' }; IEnumerable<string> singleList = ???; //singleList yields 'a', 'b', 'c', 'd' 回答1: I take it you can't just Insert into the existing list? Well, you could use new[] {element}.Concat(list) . Otherwise, you could write your own extension method: public static IEnumerable<T> Prepend<T>( this IEnumerable<T> values, T value) { yield return value; foreach (T item in values) { yield return item; } } ...