I need to create byte array for testing. I implemented my own solution but not sure if it is optimal. Here it is:
byte counter = 0;
Func<int, byte[]> createByteArray = size =>
{
var array = new byte[size];
for (int index = 0; index < size; index++)
{
array[index] = counter++;
if (counter == byte.MaxValue)
{
counter = 0;
}
}
return array;
};
Are there any ways to simplify this?
counteroutside of the function? Are you aware of potential issues with variable closure?