Using an ellipses, ...
, as was asked and answered here, allows you to initialize many indices of a C array to the same value.
Obviously this is a very useful shorthand for having all, or specific indices, of an array be a certain value, as the code required to do so is extremely short.
Is there a similar method of doing that in C#?
Let's say that I have a char
array named charArray
whose length is 50. If I wanted to have all indices to be 'h'
, I would have to do something like this, to my knowledge:
char[] charArray = new char[50];
for(int i = 0; i < charArray.Length; i++)
charArray[i] = 'h';
Can I shorten this code segment any further?
If so, how would I go about doing that?