ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2017 www.aspforums.com. All rights reserved.Index was outside the bounds of array<pre class="brush: csharp">public static void Main() { int[] number = { 1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9 }; int n = number.Length; for (int i = 0; i &lt; n; i++) { if ((i + 1) &lt; n &amp;&amp; number[i] != number[i + 1]) { Console.WriteLine(number[i]); } } }</pre> <p>&nbsp;</p>http://www.aspforums.net/Threads/943497/Index-was-outside-the-bounds-of-array/http://www.aspforums.net/Threads/943497/Index-was-outside-the-bounds-of-array/Tue, 26 Jun 2012 04:17:01 GMTIndex was outside the bounds of array<p>The code u have given does not give the error but it is not printing 9</p>http://www.aspforums.net/Threads/943497/Index-was-outside-the-bounds-of-array/http://www.aspforums.net/Threads/943497/Index-was-outside-the-bounds-of-array/Tue, 26 Jun 2012 04:34:53 GMTIndex was outside the bounds of array<p>Because of checking</p> <p><code class="csharp plain">number[i] != number[i + 1]</code></p>http://www.aspforums.net/Threads/943497/Index-was-outside-the-bounds-of-array/http://www.aspforums.net/Threads/943497/Index-was-outside-the-bounds-of-array/Tue, 26 Jun 2012 07:00:22 GMT