score:6
Accepted answer
i'm editing to turn my sample code into a method that i might almost use in production because it's more testable and culture-aware:
public ienumerable getmonths(datetime currentdate, iformatprovider provider)
{
return from i in enumerable.range(0, 12)
let now = currentdate.addmonths(i)
select new
{
monthlabel = now.tostring("mmmm", provider),
month = now.month,
year = now.year
};
}
this outputs (on a french computer):
score:8
var months =
enumerable.range(0, 12).
select(n => datetime.today.addmonths(n)).
select(d = new { year = d.year, month = d.month });
Source: stackoverflow.com
Related Query
- Linq list for month+year for the whole year
- Is there a LINQ function for getting the longest string in a list of strings?
- How to get linq `ForEach` statement to return data on the method call being made for each list object?
- How to implement SkipWhile with Linq to Sql without first loading the whole list into memory?
- Determine the source DataContext for a Linq to Sql query
- Linq query for selecting an item from tree structure, but to look in the whole depth
- What is the best way to get the percentage for an object in linq list and map it to JSON?
- Understanding the various options for runtime code generation in C# (Roslyn, CodeDom, Linq Expressions, ...?)
- Send a new list to the result of the LINQ query from the list for C#
- Get the objects with the maximum value for a specific property from a list using LINQ
- get the most recent updated record for each ID in the given list of IDs. LINQ
- Cannot build the Test project for LINQ IQueryable Toolkit (IQToolkit) - Code 9009
- Can I use a LINQ IEnumerable result as the data source for a Gtk.TreeView?
- The Same instance of a list for all elements when using Select New List<> in linq to sql
- Is there a Linq operation to retrieve specific items from a list of items where the item has a property value for a property which should be unique?
- Looking for LINQ syntax that gets the second item in a list that starts with something specific
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- LINQ entity data model generated code error - The type 'DBContexts.Category' already contains a definition for 'ID'
- Reduce the line of code for this LINQ query
- Linq lambda for searching a List within a List, finding a match, then deleting it from the list
- source code for LINQ 101 samples
- Can I Use The Same Linq Code to Query for Different Conditions?
- Linq code to get the index of an object in an array from an object within a list
- C# LINQ code for two list compare and replace
- Shortcut LINQ toentity query for the following code in MVC 3
- How do I pass a parameter from the select list into a function for joining a linq query?
- EF Core: The LINQ expression could not be translated for a nested List with Generic StartsWith() Expression
- Linq query to select the records based on the given months for a year
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- LINQ group by list and the the first/last for each grouped property
More Query from same tag
- DevExpress MVC GridView BindToLINQ() Selects Too Much Data
- Pick element from xml
- Write a complex Linq2SQL query
- Create Linq Obect Based On Another Linq Object
- Entity Framework + Linq LEFT JOIN using a where clause?
- What's the best way to compile a list of all Parent objects of a list of child objects?
- SelectMany cannot be inferred from the usage
- How to switch Key and Values in Dictionary where value might be Null
- How can I map a user-given string to an object property at runtime?
- How to write a LINQ to return results only if value is present in a pre-definded list
- I have a custom expression program with a lexer, parser and evaluator. How do I LINQ-ify it?
- Select inside linq select
- How to get one property from Ilist<T> where other properties are True
- How to get an XML attribute value with Linq to XML?
- Get item from list through for-loop
- Convert List<T> to HashTable
- C# SQL to LINQ pattern matching
- .Net Core 5 Rest Api Entity Framework Linq Expression Translation Error While Getting Record List From Controller
- LINQPAD - How do I set values to parameters when using Select after reading in lines from a file
- Get click statistics count grouped by month
- Merging two Query Results
- Create custom object from List<T> using .Linq
- Using LINQ with classes implementing non-generic ICollection
- how to remove duplicate data for group query in Linq
- C# generlized order by
- MVC C# Select Where
- Mapping in Nhibernate
- VB.net event handler abort when it is fired again
- Linq compare hour
- Compare input double with datatable string column values within a range using between query(SQL query to Linq on datatable c# )