EDN Admin
Well-known member
hello, im running the following code in c#
<pre class="prettyprint using System;
class Program
{
static void Main()
{
int val = 10;
int i;
int j;
int[][] list = new int[2][];
list[0] = new int[5] { 1, 3, 5, 7, 9 };
list[1] = new int[5] { 2, 4, 6, 8, 10};
for (i = 0; i <list[0].Length;++i)
for (j = 0; j < list[1].Length; ++j)
{
list[j] = val;
Console.WriteLine("{0}", val);
}
}
}
[/code]
<br/>
and when i run the code in the debug mode, it runs for couple seconds then it shows me the following message
<pre class="prettyprint IndexOutOfRangeException was unhanded [/code]
<br/>
and directly underneath the Indexoutofrange it show the message
Index was outside the bounds of the array.
and the it leads me to the following link
http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(EHINDEXOUTOFRANGE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(EHINDEXOUTOFRANGE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true
ive read it, but it wasnt quite clear for me so anyone here could please tell me how can i solve this problem
thanks in advance.
PS, i hope any solution wont demand any kind of change to the program structure because im ought to follow this structure, yet i will change if theres no other to way to over come the problem
thank again http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(EHINDEXOUTOFRANGE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true
View the full article
<pre class="prettyprint using System;
class Program
{
static void Main()
{
int val = 10;
int i;
int j;
int[][] list = new int[2][];
list[0] = new int[5] { 1, 3, 5, 7, 9 };
list[1] = new int[5] { 2, 4, 6, 8, 10};
for (i = 0; i <list[0].Length;++i)
for (j = 0; j < list[1].Length; ++j)
{
list[j] = val;
Console.WriteLine("{0}", val);
}
}
}
[/code]
<br/>
and when i run the code in the debug mode, it runs for couple seconds then it shows me the following message
<pre class="prettyprint IndexOutOfRangeException was unhanded [/code]
<br/>
and directly underneath the Indexoutofrange it show the message
Index was outside the bounds of the array.
and the it leads me to the following link
http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(EHINDEXOUTOFRANGE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(EHINDEXOUTOFRANGE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true
ive read it, but it wasnt quite clear for me so anyone here could please tell me how can i solve this problem
thanks in advance.
PS, i hope any solution wont demand any kind of change to the program structure because im ought to follow this structure, yet i will change if theres no other to way to over come the problem
thank again http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k(EHINDEXOUTOFRANGE);k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV4.0%22);k(DevLang-CSHARP)&rd=true
View the full article