I am not sure why you are messing it up by looping first and writing a query again in the loop. Do it either with a
foreach loop or a LINQ query like this:-
int result = items.Sum(x => x.Cost);
It will give you 210 as output.
- Convert string to int in one line of code using LINQ
- LINQ - using a query expression to calculate data time difference
- Left outer join using LINQ -- understanding the code
- How to reuse a linq expression for 'Where' when using multiple source tables
- Avoiding code repetition when using LINQ
- Using LINQ to delete an element from a ObservableCollection Source
- LINQ Source Code Available
- Calculate Percentile using LINQ
- How can I write the following code more elegantly using LINQ query syntax?
- How can I code an outer join using LINQ and EF6?
- How do I calculate a checksum on all columns in a row using LINQ and Entity Framework?
- C# .Net 3.5 Code to replace a file extension using LINQ
- Calculate sum using LINQ
- Trying to understand LINQ code using c#
- Retrieve bool result by using LinQ code
- calculate the total time grouping by date and id using linq
- creating Linq to sqlite dbml from DbLinq source code
- read icollection data using LINQ in C# code
- C# - Code supposed to be unreachable when calculate value in LINQ sum method
- Linq sub query when using a repository pattern with EF code first
- How to calculate a running total using linq
- ICollection<T> calculate average per hour using LINQ
- Using LINQ query result for data source for GridControl c#
- How to calculate count on of table column using group by clause in linq
- How to flatten a multi level XML into a single level XML using c# code LINQ
- Using Linq to build a graph class; can you make this code look better?
- Calculate average difference between a series of DateTime objects using LINQ
- How to write this code using the Linq Extension Method-Syntax?
- Code Rewite for tuple and if else statements by using LINQ
- How can I check the number of calls to the database in LINQ query when using .NET Core and Code First?
- LINQ Select Customized Random-ness
- Select Distinct with Linq to Entities
- Sorting a list in C# with special characters
- Expression tree ToString with format/culture
- C# - How to create a KeyValuePair with the result of two foreach loops?
- using a FUNC method (selector) to return a "light version" of my list
- Return ViewModel instead of Model
- Filter some unique Data with LINQ and C#
- How do I use linq to fill dictionary with default values?
- Should i use .ToList().Distinct() or .Distinct().ToList()?
- Query multiple oracle schemas in LINQPAD with IQ driver
- EF: Select columns where any of them has value but not all of them
- Calculate Account Receivables using LINQ
- Linq Orderby vs SQL Orderby
- how do you split up or join a linq query on an "or" (without using Union)?
- C# LINQ GroupBy error Only one expression can be specified in the select list
- How to perform Join between multiple tables in LINQ lambda
- Linq Group By Sum based on a condition
- Is it possible to build a complex query using expression tree
- How use Long type for Skip in Linq