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
Hudikwebb IT
NA
21
632
Sum of duplicated items Tuple C#
Aug 16 2018 2:23 PM
I have a data in a tuple C# I will calcaulate the sum of the last column grouped by month. my program gives wrong results as shown in the table below.
The program is here :
var q1 = from x
in
Vinst
group x by x.Item1 into g
let count = g.Count()
orderby count descending
select
new
{ Value = g.Key, Count = count};
double
sum = 0.0;
//= (from x in Vinst where x.Item1.Equals("augusti") select x.Rest.Item2).Sum();
int
k = 0;
foreach
(var lst
in
Vinst)
{
sum += lst.Rest.Item2; k++;
richTextBox7.AppendText(
"Vinst Data"
+
"\t"
+ lst.Item1 +
"\t"
+ lst.Item2 +
"\t"
+ lst.Item3 +
"\t"
+ lst.Item4 +
"\t"
+ lst.Item5 +
"\t"
+ lst.Item6 +
"\t"
+ lst.Item7+
"\t"
+ lst.Rest.Item1 +
"\t"
+ lst.Rest.Item2 +
"\n"
);
foreach
(var x
in
q1)
{
if
(k == x.Count)
richTextBox7.AppendText(
"\nData summa"
+
" "
+ sum +
"\n"
);
}
}
july GBP 6000 13 400 19500 1500 5200 800
Data sum 800
july SAR 1000 2 400 1200 600 800 200
july USD 4500 8.95 500 15993 1787 4475 25
Data sum 1025
august USD 5700 8.5 600 5950 700 5100 600
The correct result should be like this
july GBP 6000 13 400 19500 1500 5200 800
july SAR 1000 2 400 1200 600 800 200
july USD 4500 8.95 500 15993 1787 4475 25
Data sum 1025
august USD 5700 8.5 600 5950 700 5100 600
data sum 600
Reply
Answers (
3
)
compare validation in asp.net for negative numbers
casting byte[] in c#