1

如何添加下面代码片段中注释的 if 语句?

Dictionary<string,int> toReturn;
List<string> lookup = GetIt();

foreach (string test in lookup)
{
    var testDictionary = ToGroupDictionary(test);
    testDictionary.Keys.ToList().ForEach(k =>
        //if(true){add toReturn list}
    );
}
4

2 回答 2

4

只需要添加花括号:

testDictionary.Keys.ToList().ForEach(k => 
{
    //if(true){add toReturn list}
});
于 2012-08-26T00:47:34.727 回答
3

或者添加一个Where子句

testDictionary
  .Keys
  .Where(k => conditional(k))
  .ForEach(k => { /* something else */ } );
于 2012-08-26T00:49:11.493 回答