Steven's Dev Blog
Tips to remind for the FUTURE.
Wednesday, December 7, 2011
Linq calculate average of a list C#
Only one line of code will do it:
List
<
float
> f =
new
List
<
float
>();
for
(
int
i = 0; i < 10; i++)
{
f.Add((
float
)i);
}
float
ave = f.Aggregate((acc, cur) => acc + cur) / f.Count;
Console
.WriteLine(ave);
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment