Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resetting a char array

Tags:

arrays

c#

I'm having a char array :

public static char[] boardposition = new char[9];

I want to reset the array , my written function for this is:

public static void Reset()
{            
     Array.Clear(boardposition,9, boardposition.Length);
}

When I call the Reset() I get an exception of type IndexOutOfRangeException.

I hope you guys can help me out.

like image 415
Elvira Avatar asked Dec 29 '25 13:12

Elvira


1 Answers

You are passing 9 as starting index wich isn't a valid index for your array. Make the call like this Array.Clear(boardposition,0, boardposition.Length);

like image 112
alessio bortolato Avatar answered Jan 01 '26 03:01

alessio bortolato



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!