5

I declare a Byte-Array like this:

Byte[] b = new Byte[10];

and assign some values:

for (int i=0; i<b.Length; i++)
{
    b[i] = 1;
}

Now I want to zero the array again and call:

b.Initialize(); 

which doesn't work. The array remains unchanged. Isn't b a value-type array?

1
  • 1
    Array.Clear is probably what you're looking for Commented Jul 14, 2011 at 18:41

1 Answer 1

11

See MSDN:

Caution

You can use this method only on value types that have constructors; however, value types that are native to C# do not have constructors.

byte is native.

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

4 Comments

Perhaps most telling from the MSDN article: "This method is designed to help compilers support value-type arrays; most users do not need this method."
@Marc: Right, I didn't read the caution note in MSDN carefully enough.
@Ramhound no, it will do no such thing. That creates a new array ; it resets nothing except for the variable. It absolutely does not reinitialize the array.
Is the method intended for use with languages that allow value types to have non-trivial default constructors?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.