문제

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