score:1
double tickperday = (double)(24.0 * 60.0 * 60.0 * 10000000.0);
list<mytype> datalist = new list<mytype>() {
new mytype() { filename = "file_1", index = 1, time = (datetime.parse("1/1/1900").adddays(42038)).addticks((long)(tickperday * .6924500000))},
new mytype() { filename = "file_2", index = 2, time = (datetime.parse("1/1/1900").adddays(42038)).addticks((long)(tickperday * .6435300000))},
new mytype() { filename = "file_3", index = 3, time = (datetime.parse("1/1/1900").adddays(42038)).addticks((long)(tickperday * .7962800000))},
new mytype() { filename = "file_4", index = 4, time = (datetime.parse("1/1/1900").adddays(42038)).addticks((long)(tickperday * .9340600000))},
new mytype() { filename = "file_5", index = 2, time = (datetime.parse("1/1/1900").adddays(42038)).addticks((long)(tickperday * .9561300000))},
new mytype() { filename = "file_6", index = 1, time = (datetime.parse("1/1/1900").adddays(42039)).addticks((long)(tickperday * .9561300000))},
new mytype() { filename = "file_7", index = 4, time = (datetime.parse("1/1/1900").adddays(42039)).addticks((long)(tickperday * .5551700000))},
new mytype() { filename = "file_8", index = 2, time = (datetime.parse("1/1/1900").adddays(42038)).addticks((long)(tickperday * .9652200000))},
new mytype() { filename = "file_9", index = 1, time = (datetime.parse("1/1/1900").adddays(42039)).addticks((long)(tickperday * .0111500000))},
new mytype() { filename = "file_10", index = 3, time = (datetime.parse("1/1/1900").adddays(42039)).addticks((long)(tickperday * .0990100000))}
};
int maxindex = datalist.max(x => x.index);
var results = datalist.groupby(x => x.index)
.select(x => enumerable.range(1, maxindex)
.select(y => x.any(z => z.index == y) ? x.where(z => z.index == y).firstordefault() : new mytype() { filename = "file_spacer", index = y, time = datetime.parse("1/1/1900")})
.tolist())
.tolist();
Source: stackoverflow.com
Related Query
- c# Linq or code to extract groups from a single list of source data
- Using LINQ to extract ints from a list of strings
- Extract data from a XML string using linq vs xmlDocument
- How does linq actually execute the code to retrieve data from the data source?
- Get groups of 4 elements from name value list using LINQ in C#
- LINQ DynamicLibrary: How to extract count and list from IQueryable
- using linq select from list data where
- Is a full list returned first and then filtered when using linq to sql to filter data from a database or just the filtered list?
- creating Linq to sqlite dbml from DbLinq source code
- Populate Nested List of Classes from single data table c#
- C# LINQ How to get a data source from a db?
- Extract list of objects from a string using linq
- Using LINQ to copy data from one list to another
- Create list of tuples with data from nested lists with Linq
- What is correct Linq syntax to get multiple aggregate results from a list of integers in single iteration
- Group and Merge multiple values from single List using LINQ
- Using Linq to extract data from a Table
- Use LINQ to populate a single list from two other lists without duplicates
- Extract the data from a SelectedItem event from a LINQ filled DataGrid
- How can I extract data from a list of parent objects with children?
- How can I use Linq to extract this data from a List?
- LINQ - Return data from list 2 occurrences
- How to extract items at specified locations from list of comma separated strings using LINQ
- Add List objects from a single list to a new List using LINQ
- Use LINQ to populate a single list from two other lists
- C# LINQ Remove multiple objects from a list in single execution
- Linq query for updating list of objects with some data from another list of objects
- Linq - Get groups of elements from List between two elements of the same type
- How to extract values from a list of dictionaries and group and convert to a single dictionary with Linq?
- Linq code to get the index of an object in an array from an object within a list
More Query from same tag
- Is it possible to use Skip and Take whilst calculating an Average?
- query too slow - get and update records with linq query
- Specified cast not valid calling stored procedure
- Linq get records based by in clause and sort by
- Creating associations in a dbml file?
- How to find missing items with GroupBy in LINQ?
- How can I add two conditional filters to the same IEnumerable?
- Remove duplicate entries from an XDocument
- C# Complex Linq - Join two table within a subquery
- How to return substring of linq results
- C# Convert a DataTable to List<string>
- Dynamic Linq and Where Clause & NOT Contains
- Multiple Select using LINQ
- List of class properties
- How do I select everything after the last instance of?
- MVC linq keeps returning the last row of data
- Joining queries with Entity Framework
- LINQ returning EnumerableRowCollection
- LINQ Sum with GroupBy
- LINQ method with varying parameters
- Debugging LINQ to SQL SubmitChanges()
- Total Sum with multiple where clause LINQ
- The LINQ expression 'GroupByShaperExpression: could not be translated while using GROUPBY in LINQ query
- Medium to Advance LINQ/EntityFramework Query question. taggings items
- LINQ filtering on data only works during debug
- how to Check for equality with list input in linq
- VB.NET LINQ Join 2 tables , then group by a column then sum
- Convert List<T> to List<string> generically
- Understanding Deferred Execution: Is a Linq Query Re-executed Everytime its collection of anonymous objects is referred to?
- How do i use filter in linq against non string fields?