score:10
This can be achieved using Enumerable.Range
List<int> integerList = Enumerable.Range(MinValue, MaxValue - MinValue).ToList();
score:3
Just use the Enumerable.Range(int start, int count)
method:
Generates a sequence of integral numbers within a specified range.
A simple example, using your MinValue
and MaxValue
variables:
List<int> integerList = Enumerable.Range(MinValue, MaxValue - MinValue).ToList();
Note that if MaxValue
is less than MinValue
, the count
parameter will be less than zero and an ArgumentOutOfRangeException
will be thrown.
score:1
You could use a collection initializer.
http://msdn.microsoft.com/en-us/library/bb384062.aspx
private List integerList = new List{MinValue, MaxValue};
score:2
Assuming MaxValue is always > MinValue,
var integerList = Enumerable.Range(MinValue, MaxValue-MinValue).ToList();
score:1
You could use Enumerable.Range
List<int> integerList = Enumerable.Range(MinValue, MaxValue - MinValue).ToList();
score:1
Try IEnumerable.Range(MinValue, MaxValue-MinValue).ToList(): MSDN
Source: stackoverflow.com
Related Articles
- Initialize a List<int> with LINQ query
- Linq sub query when using a repository pattern with EF code first
- Avoiding repeating code with Linq query + optional params
- how to write a Linq query with a EF code first Many to Many relationship
- Cannot initialize TimeSpan with a collection initializer in linq query ¿Syntax error?
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Linq query with nullable sum
- Problem with linq query
- Nested "from" LINQ query expressed with extension methods
- How to use index/position with Where in LINQ query language?
- Linq query with Array in where clause?
- Casting to a derived type in a LINQ to Entities query with Table Per Hierarchy inheritance
- How do I most elegantly express left join with aggregate SQL as LINQ query
- How to query an XDocument with LINQ when elements have a colon in their name?
- LINQ query with Distinct and Union
- Selecting multiple columns with linq query and lambda expression
- GroupBy with linq method syntax (not query syntax)
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Simplify process with linq query
- LINQ To SQL: Delete entity (by ID) with one query
- How/Can I use linq to xml to query huge xml files with reasonable memory consumption?
- query a sub-collection of a collection with linq
- Linq query with multiple Contains/Any for RavenDB
- LINQ select query with Anonymous type and user Defined type
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- Entity Framework - Linq query with order by and group by
- Linq Query with SUM and ORDER BY
- Linq Query with a Where clause in an Include statement
- Ordering linq query with secondary sort
- How to PLINQ an existing LINQ query with Joins?
- Where does the LINQ query syntax come from?
- Cleanup String: Replace consecutive nonalphanum Character with single seperator
- Insert using linq templates not returning the id - MySQL
- Optimize Code by using yield or changing algorithm
- Entity Framework update is not updating database table
- LINQ - Aggregate and calculate several parameters
- C# linq to entity include with condition and ordering
- Nested classes using entity framework and linq
- Linq query for creating PIVOT table
- Convert a for loop to linq
- How do i filter one list from another list using linq
- Group by Question in Linq
- EntityFrameworkCore Linq error: variable 'country.Country' of type 'Country' referenced from scope '', but it is not defined
- How to edit element of List of Lists?
- How to project EF Linq result to IEnumerable<IBook> where Book Explicitly implements in IBook?
- Entity Framework - getting a table's column names as a string array
- Returning the first possible node's inner text in a XML file
- LINQ query that calls some method for additional calculations
- How to convert Linq Expression<Func<object,object,bool>> to Expression<Func<T1,T2,bool>>
- Convert function to LINQ to SQL