title: Initializing a C# array with multiple copies of the same element
body: <p>In the C++ Standard Template Library (STL), it is possible for example to create a vector consisting of multiple copies of the same element, using this constructor:</p>
  
  <pre><code>std::vector&lt;double&gt; v(10, 2.0);
  </code></pre>
  
  <p>This would create a vector of 10 doubles, initially set to 2.0.</p>
  
  <p>I want to do a similar thing in C#, more specifically creating an array of <em>n</em> doubles with all elements initialized to the same value <em>x</em>.</p>
  
  <p>I have come up with the following one-liner, relying on generic collections and LINQ:</p>
  
  <pre><code>double[] v = new double[n].Select(item =&gt; x).ToArray();
  </code></pre>
  
  <p>However, if an outsider would read this code I don't think it would be immediately apparent what the code actually does. I am also concerned about the performance, I suppose it would be faster to initialize the array elements via a <em>for</em> loop (although I haven't checked). Does anybody know of a cleaner and/or more efficient way to perform this task?</p>