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 Articles
- Linq list for month+year for the whole year
- c# Linq or code to extract groups from a single list of source data
- How to implement SkipWhile with Linq to Sql without first loading the whole list into memory?
- LINQ Source Code Available
- LINQ query returns old results when source list is re-initialized
- C# - Linq optimize code with List and Where clause
- creating Linq to sqlite dbml from DbLinq source code
- C# LINQ create month and year list
- Code practice to handle empty result set in Linq to custom list
- Linq extension. Change property value in source list
- source code for LINQ 101 samples
- Linq code to get the index of an object in an array from an object within a list
- How to sort list on multiple properties in one line of code in Linq
- C# LINQ code for two list compare and replace
- LINQ function to return list but compiler says function doesn't return a value on all code path
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- Filtering whole of hierarchical list with LINQ
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- Create a tree structure in linq with a single list source with parent - child as strings of an object
- Construct a list of wpf Hyperlink elements from an XML source file using Linq
- List or Array of String Contain specific word in Html Source Code
- Fetch month and Year Inside a List using Linq
- Linq to entities hard code list
- Complex SQL to LINQ to populate Grid (Count items year by month) (MVC, EF Code First)
- Updating List using LINQ working when execute from Immediate window, not from code direct
- EF LINQ to SQL is getting whole table from DB instead of selection - where clause contains list with Any statement
- How to write SQL translateable linq code that groups by one property and returns distinct list
- C# LINQ find duplicates in List
- Split List into Sublists with LINQ
- Flatten List in LINQ
- LINQ Casting issue
- How to traverse through attributes in xml through LINQ
- Linq FirstOrDefault evaluates predicate each iteration?
- How can I fully load a recursive model on multiple levels with entity framework?
- call stored procedure with linq
- Which one of this syntaxs have better performance?
- Why does my Lambda query return an anonymous type versus Linq's strongly-typed return value?
- Or() expression in linq
- Is there an equivalent in LINQ for the SQL Server PARTITION OVER functionality?
- How to include only some items of internal list with LINQ to Entities
- `SELECT MIN(ZoneMin), MAX(ZoneMin) FROM Plant` as LINQ to SQL
- LINQ to SQL selecting all records which have any word in the string split
- LINQ on Directory.GetFiles with Substring in Where clause
- Cannot get distinct values using a SelectListitem
- How to use left outer join in LINQ for SQL query?
- With Entity Framework is it better to use .First() or .Take(1) for "TOP 1"?
- Restructuring object
- Fluent NHibernate: Query a many to many relation
- Using linq on OrderedDictionary to obtain max with GridView
- Only parameterless constructors and initializers are supported in LINQ to Entities message