IEnumerable类型原生是没有Add方法的,你可以用Contact方法去为它添加元素,
|
1
|
items = items.Concat(new[] { "foo" }); |
也可以用个扩展方法:
|
1
2
3
4
5
6
|
public static IEnumerable<T> Add<T>(this IEnumerable<T> e, T value) { foreach ( var cur in e) { yield return cur; } yield return value;} |