score:10
this can be achieved using enumerable.range
list<int> integerlist = enumerable.range(minvalue, maxvalue - minvalue).tolist();
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: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
score:2
assuming maxvalue is always > minvalue,
var 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.
Source: stackoverflow.com
Related Query
- 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?
More Query from same tag
- Linq select all and additional calculated field
- Using Reactives to Merge Chunked Messages
- Unable to cast object of type 'System.Data.EnumerableRowCollection`1[System.Int32]' to type 'System.IConvertible'
- Nested Linq queries Microsoft Azure
- LINQ to Entities does not recognize the method 'System.String get_Item(Int32)' method, and this method cannot be translated into a store expression
- Am I using QueryOver wrong?
- How to get a set number of rows after ordering the records using linq?
- Selecting according to a Min or Max on one value in LINQ
- How to remove first occurence of element in List C# with LINQ?
- LINQ- How to select distinct records against distinct column
- LINQ join - two objects by different "type" of parameters
- How to change values in IQueryable field in C# with LINQ
- GroupBy in LINQ?
- Resolve ParameterExpression to actual Expression
- C# search a list using groupby and where
- Getting 2 Top 5 within a single LINQ query in EFCore
- EPPlus Excel Export - All data values going into Column A for each record?
- Linq To Entities Exclude Related Data
- Divide Db Query Result into as many tasks as I want
- Need help with LINQ to SQL WHERE-clause on foreign table
- Linq query to sort strings like numbers in ASP.NET-Core 3.0 and above
- Linq Lambda join breaks when joining a table
- Linq2Sql select where string is NOT null or empty
- Group a datatable by sequential values
- Intersect two collections which contain different types
- Linq: OrderBy dynamic nested property which can be null
- Lambda expression question
- Comparing column with column using linq query
- Using LINQ to check if a string contains a list of strings or characters
- Prevent LINQ to SQL from returning child objects