TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
S Lemen
NA
7
15.8k
Aggregate and foreach return different values
Dec 12 2010 1:59 PM
Hi,
In the code below, the Linq aggregate Agg.Sum_Of_Squares and the double ret, after the foreach loop, have different values. Agg.Sum_Of_Squares = 66.55 but ret = 69.19. Should not both statements return the same value?
Thank you,
Scott
double
ret = 0;
double
[] values = { 2.2, 2.3, 3.3, 4.1, 5.6 };
var
Agg =
new
{
Sum_Of_Squares = (
from
v
in
values
select
v).Aggregate((cnt, v) => cnt += (v * v))
};
foreach
(
double
v
in
values)
{
ret += (v * v);
}
Reply
Answers (
2
)
Translate Linq Aggregate from VB to C#
How to read in XML to a textbox