Manipulating collections using Linq

Code sample article
Table of Contents
Summary

Sample code for handling objects of the type collection using Linq

Operations
Initialize an array
How to do it
 // Init an array with the same value
int[] col1 = Enumerable.Repeat(-1, 10).ToArray();

// Init an array with an increment value
int[] col2 = Enumerable.Range(0, 10).ToArray();

// Init an array with calculated values
int[] col3 = Enumerable.Range(0, 10).Select(i => 100 + 10 * i).ToArray();
Generate a random sequence of length N
How to do it
 Random rand = new Random();

// Generate random sequence of 10 random elements
var enum1 = Enumerable.Repeat(0, 10).Select(i => rand.Next());
enum1.ToList().ForEach(i => Console.Write(i.ToString() + " "));
1778126577 544608089 1716043764 1230172478 1465246133 1785379093 1016466291 447404671 1519246728 566498977