3

I have an array called Buffer. I am using a for loop to initialize its contents to 0. How do I do it in a single statement in C#? I do not want to use the for-loop.

byte[] Buffer = new byte[50];
int arrC = 0;
// array initialization
for (arrC = 0; arrC < 50; arrC++)
{
    Buffer[arrC] = 0;
}
2

1 Answer 1

13

You don't, and you don't have to. The default value for a byte is 0.

Hence, if you create an array of type byte[], each item in the array has the default value 0.

Sign up to request clarification or add additional context in comments.

1 Comment

Why the downvote? This answer is correct. If you have a better answer, please post it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.