score:15
Accepted answer
int numOfEvents = eventsForAllMonths.SelectMany(m => m.AllDays)
.Select(d => d.CalEvents.Count)
.Sum();
score:0
I ForEach()
for a living, so:
eventsForallMonths.ForEach(em=>em.ForEach(ed=>numOfEvents+=ed.CalEvents.Count));
score:0
How about transforming this in lambda?
List<Item> listItem = new List<Item>();
foreach (StackPanel sp in spPhotos.Children)
{
foreach(Item item in sp.Children)
{
listItem.Add(item);
}
sp.Children.Clear();
}
spPhotos.Children.Clear();
score:2
Try this:
private int getNextEventId()
{
int numOfEvents = eventsForAllMonths.SelectMany(eventMonth => eventMonth.AllDays).Aggregate(0, (current, eventDay) => current + eventDay.CalEvents.Count);
return numOfEvents + 1;
}
score:2
How about this?
return
(from m in eventsForAllMonths
from d in m.AllDays
select d.CalEvents.Count).Sum() + 1;
score:3
return (eventsForAllMonths.SelectMany(eventMonth => eventMonth.AllDays).Sum(eventDay => eventDay.CalEvents.Count) + 1);
Source: stackoverflow.com
Related Query
- How do I convert this double foreach loop to just lambdas?
- How to convert this foreach loop into Linq code?
- how can I convert this foreach loop to linq?
- How to convert the following foreach loop to linq code format?
- How to get Resharper to convert back to a foreach loop
- How to convert foreach loop to a Linq query?
- I want to convert this foreach loop to a LINQ statement
- convert foreach loop to linq code
- How to convert Foreach loop to Linq (in datagridview)
- How might I convert this SQL code to LINQ?
- How do i convert this linq code to inline sql
- Linq Puzzle: How do I convert this foreach to linq syntax?
- How to convert this recursive code to Linq
- How to convert this code to LINQ?
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- How to code a Foreach Loop for Endless Categories Tree in MVC.Net?
- Linq - how to convert this code to linq
- How can I convert Foreach loop with Linq expression OR AsEnumerable in C#.net?
- How to convert this sample foreach into lambda expression?
- How to convert the foreach loop to linq
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- how to convert var to dictionary and access var using foreach loop
- How can I convert foreach loop to LINQ lambda
- Convert the code from Foreach loop to Linq
- How to convert the following foreach nested loop to LINQ?
- How do I convert this loop into a LINQ expression?
- How can i convert this code snippet into LINQ format?
- How to convert the following foreach loop to linq format?
- How to perform this foreach loop I need?
- How do I convert this looped code to a single LINQ implementation?
More Query from same tag
- How could I query average and group by using LINQ in ASP.NET C#
- LINQ intersect, multiple lists, some empty
- cosmos db LINQ query in documentation
- How to merge trees (and sum counts) using LINQ?
- Run multiple IQueryable's at single point of execution
- Filter data in dataset using LINQ and get result as list of strings
- Unable to create a constant value of type 'System.Object'
- Is there a better way to formulate this entity framework 4 update?
- Filter a IEnumerable<string> for unwanted strings
- Using an IEqualityComparer with a LINQ to Entities Except clause
- IEnumerable .Select() Not Working
- LINQ - Convert List to Dictionary with Value as List
- Can I allow queried objects to affect the query that fetches them with Linq and NHibernate?
- Create an ObservableCollection by filtering two ObservableCollections of the same type using LINQ and MVVM
- How do I get the auto generated Id?
- Delete Files that are more than than 10 days old using Linq
- Merge N amount of DataTables while summing one of the columns
- Date formatting from model is not working for datatype date
- Data Loading Strategy/Syntax in EF4
- What is a possible interface to return for Entity framework entity classes?
- Getting a value from database column using Linq C#
- Does LINQ to Entities reuse instances of objects?
- LINQ GroupBy and Select on different property
- Group by and Select with Models
- How do I link 3 tables using foreign keys?
- Max or Default?
- Property setter trims a value assigned from LINQ, but isn't displayed as such in WPF datagrid
- Can I use OrderBy<T> to order by a Join<T> entity?
- Linq to Entities Querying for Nullable data types
- LINQ, how to specify to include items from List<>