score:14
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.
Source: stackoverflow.com
Related Query
- Calculate sum using LINQ
- C# - Code supposed to be unreachable when calculate value in LINQ sum method
- Using Linq Calculate sum of ObservableCollection value
- Calculate sum of each row using LINQ
- How to calculate sum on a datable column using linq with a where clause?
- Calculate sum of column using group by in Linq
- Convert string[] to int[] in one line of code using LINQ
- Using GroupBy, Count and Sum in LINQ Lambda Expressions
- Using Linq to sum up to a number (and skip the rest)
- How to calculate sum of a DataTable's Column in LINQ (to Dataset)?
- using LINQ to find the cumulative sum of an array of numbers in C#
- Using LINQ to group by multiple properties and sum
- Exception when using LINQ SUM
- Using Linq to GroupBy and Sum datatable
- Multiple SUM using LINQ
- Convert a list to a dictionary and sum up values using linq
- How to do a Sum using Dynamic LINQ
- Using sum method in LINQ
- Problem with LINQ to Entities query using Sum on child object property
- Merging 2 lists and sum several properties using LINQ
- LINQ - using a query expression to calculate data time difference
- How can I calculate sum of column value in linq to sql query?
- 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
- How to sum Timespan of subtraction between two datetimes in Linq when using group by?
- LINQ Source Code Available
- Calculate Percentile using LINQ
- how to filter and sum using linq
More Query from same tag
- linq lambda composite key where and group by
- Using Expression<Func<TSource, TKey>> with IQueryable
- Nullable int not working as expected in LINQ (C#)
- Searching in xml with linq
- How can I insert an XElement into an existing xml-file?
- Getting a System.NotSupportedException when using MongoDB.Driver.Linq
- Selecting from xml based on attributes in multiple subnodes
- ASP MVC5 LINQ Multiple Selects with Lists
- How to: Explicit Anonymous declaration
- LINQ Query that is able to identity a Row in a Junction Table with two variables - How to do it?
- Need to change the query in the recent modified date with distinct of record ids
- Dynamic Linq Query Help?
- How to view LINQ Generated SQL statements?
- linq query distinct date
- Get Unique Item only Azure
- How to get records if only all of the list elements included in nested collections?
- System.InvalidCastException: Specified cast is not valid. Error
- Using LINQ in .Net 3.1 to get all items from a database table that matches a list of ID's
- How to calculate number of leap years between two years in C#
- Link a reflection property to a variable
- DeleteObject from multiple tables
- Compiled LINQ joins
- Why does my Linq query throw an exception when I try and sort on DateTime?
- How to load only the first related data with EF Core
- How to use function max for auto number?
- Using C# & LINQ how can I find duplicate file names?
- Creating a list of names that cannot be duplicate (if duplicate add number to name)
- Why this Linq code always throws System.StackOverflowException?
- The .NET Standard Query Operators - emptyOrder
- Grabbing Just The Top Entry From A LINQ Query