score:3
Accepted answer
var amounts = files.todictionary(
file => new {file.name,file.year}, file => file.amount);
foreach(var name in files.select(file => file.name).distinct())
foreach(var year in files.select(file => file.year).distinct())
{
decimal amount;
if(!amounts.trygetvalue(new {file.name,file.year}, out amount) amount = 0m;
console.writeline("name={0}, year={1}, amount={2}",
name, year, amount);
}
score:0
public class file
{
public file() { this.amout = 0; }
public string name{get;set;}
public int year{get;set;}
public decimal amount{get;set;}
}
Source: stackoverflow.com
Related Query
- Generate missing list values in c# list using Linq
- How to add list of missing values in c# list using Linq
- How to select values within a provided index range from a List using LINQ
- Get indexes of all matching values from list using Linq
- Convert dictionary values to list using linq
- Select distinct values from a list using LINQ in C#
- Convert a list to a dictionary and sum up values using linq
- Find the Second Max in a list of values using linq c#
- Group by key and send values into list using LINQ
- Assign values from one list to another using LINQ
- Generate a map of list element indices using Linq
- How to generate a unique list of items from another list using LINQ in C#
- Summing similar values with a list using Linq
- I need to compare list with Datatable and filter values using Linq
- How should i use group by and sum on different values of list of models using linq
- Adding a range of values in to a List using LinQ
- How to check if two values exist in a list using linq in c#
- Count the number of Enum values in list using Linq
- Using Linq to check if a list includes null values in the middle
- Get the set of grouped values as a list using linq
- Group and Merge multiple values from single List using LINQ
- C# LINQ Filter list of complex objects by sub-list using a list of values
- Select distinct values from a list using LINQ
- Formatting a string using values from a generic list by LINQ
- Update List from another List with Matching values using Linq
- Not able to select values from right list using LINQ join
- Find list of values for item using Linq
- How to retrieve the values from list using indexes by linq query?
- Adding missing dates to list between maximum and minimum date in LIST using LINQ
- Filter linq query results using values from a list
More Query from same tag
- Dynamic Linq query issue
- Fast selection of elements from a set, based on a property
- Calling a SQL User-defined function in a LINQ query
- XElement .Value swallows embedded XML
- Entity Framework, Is there any performance improvement on querying at repository instead at service layer?
- Find Any string contains List<>
- Get selected values after joining multiple tables in Entity Framework 6 using Lambda
- How to write nested group by LINQ query with sub-expression?
- C# LINQ: How to find IList<Peak>.Max?
- Order By Date print Latest 20 records only in LINQ
- How can I use the MYSQL BIT_COUNT function through nhibernate/fluent nHibernate?
- How do we switch from Telerik Open Access to anything else?
- Populate DataTable with LINQ in C#
- How should I 'rotate' or 'flatten' this research data? PIVOT, self join or something else?
- How to create Func<TSource> to Expression<Func<TSource,TValue>>
- LINQ query with value from dropdown to compare with data
- Insert Unicode string to DB using Linq
- Linq memory question
- LINQ Group by and Count by column
- How do you re-use select statements with Entity Framework?
- Linq data base insertion error
- How to use group by on a DataTable in LINQ?
- Get Reports for next 10 days in single database hit
- C# merging two object lists
- Will passing `this` inside of a `.Where` clause's predicate cause it to mutate?
- ASP.NET GridView - Object reference not set to an instance of an object
- Convert list result to datatable using linq?
- Calling functions in a LINQ query
- msbuild for .NET 3.5 issue with csla and System.Linq
- LINQ - Group By child property