相关疑难解决方法(0)

为什么IList <T>上的.ForEach()而不是IEnumerable <T>?

可能重复:
为什么IEnumerable接口上没有ForEach扩展方法?

我注意到在编写LINQ-y代码时,.ForEach()是一个很好用的习惯用法.例如,这是一段代码,它接受以下输入,并产生这些输出:

{ "One" } => "One"
{ "One", "Two" } => "One, Two"
{ "One", "Two", "Three", "Four" } => "One, Two, Three and Four";
Run Code Online (Sandbox Code Playgroud)

和代码:

private string InsertCommasAttempt(IEnumerable<string> words)
{
    List<string> wordList = words.ToList();
    StringBuilder sb = new StringBuilder();
    var wordsAndSeparators = wordList.Select((string word, int pos) =>
        {
            if (pos == 0) return new { Word = word, Leading = string.Empty };
            if (pos == wordList.Count - 1) return new { Word = word, Leading = " …
Run Code Online (Sandbox Code Playgroud)

c# linq ienumerable list c#-3.0

52
推荐指数
3
解决办法
3万
查看次数

WCF OperationContract - 我应该公开哪种通用集合类型?

我有一个WCF Web服务,它有一个返回泛型集合的方法.现在,我的问题是:我应该公开为ICollection<T>,List<T>,IList<T>,IEnumerable<T>或其他什么东西?

我想这List<T>不可能的,因为我想避免CA1002错误,但底层类型将是一个List<T>.

我真的很想听听你对此的看法,最好能够很好地解释你为什么这么想.

提前致谢

c# collections wcf operationcontract

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

c# ×2

c#-3.0 ×1

collections ×1

ienumerable ×1

linq ×1

list ×1

operationcontract ×1

wcf ×1