So instead of writing a looping function where you instantiate an array and then set each index value as the index, is there a way to do this in LINQ?
Create an Array Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array, define the variable type with square brackets: string[] cars; We have now declared a variable that holds an array of strings.
LINQ allows us to write query against all data whether it comes from array, database, XML etc.
Range overview. It takes two arguments. First argument is the first number in sequence (e.g. 10, means that the first number in sequence is 10). Second argument is the number of items in sequence (e.g. 11 means that it will return 11 numbers).
Enumerable.Range(0, 10)
will give you an IEnumerable<int>
containing zero to 9.
You can use the System.Linq.Enumerable.Range
method for this purpose.
Generates a sequence of integral numbers within a specified range.
For example:
var zeroToNineArray = Enumerable.Range(0, 10).ToArray();
will create an array of sequential integers with values in the inclusive range [0, 9].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With