I've got a following command:

var sum = myList.Sum(p => p.Field);

Is it possible to write the same command using from clause? eg.

var sum = from myList ...
有帮助吗?

解决方案

There is no expression for sum in this notation. Here is as close as you can get:

var sum = (from p in myList select p.Field).Sum();

其他提示

Yep. See below.

var sum = (from p in myList
           select p.Field).Sum();
var sum = (from p in myList
           select p.Field).Sum();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top