lambda表达式中的C#unchecked关键字

时间:2015-07-31 09:45:12

标签: c# linq lambda

我使用linq aggregate()和可能的Int32溢出:

items.Aggregate(0, (acc, item) => { unchecked { return acc * 10000 + item.Id; } });

有没有办法简化表达?

像async例如:

async () => {}

2 个答案:

答案 0 :(得分:7)

您可以摆脱<div class="row"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 positon-relative-block-down"> <p class="down">Lorem Ipsum is simply dummy</p> </div> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 positon-relative-block-up"> <p class="up">Lorem Ipsum is simply dummy Lorem Ipsum is simply dummy</p> </div> <div class="col-lg-7 col-md-7 col-sm-8 col-xs-11 positon-relative-block-describe"> <p class="describe">Lorem Ipsum is simply dummy Lorem Ipsum is simply dummy</p> </div> </div> {}声明:

return

答案 1 :(得分:2)

出于好奇,我做了一些测试......这很有效:

unchecked 
{
    int res = items.Aggregate(0, (acc, item) => acc * 10000 + item.Id);
    Console.WriteLine(res);
}

(我创建的测试应用为checked,因此,如果我删除unchecked,我会获得OverflowException