【发布时间】:2018-06-24 16:27:36
【问题描述】:
using System.IO;
using System;
class Program
{
static void Main()
{
string s1="iamamamok";
string s2="mam";
int i=0,j=0;
int count=0,countchar=0;
while(j<s2.Length)
{
while(i<s1.Length)
{
if(s1[i]==s2[j])
{
countchar++;
j++;
if(countchar==(s2.Length))
{
count +=1;
j=0;
countchar=0;
}
}
else
{
j=0;
countchar=0;
}
i++;
if(i==s1.Length)
{
break;
}
}
}
Console.Write(count);
}
}
当我尝试运行此代码时,它会使数组索引超出范围,但我尝试涵盖这些字符串的所有可能情况,请解释为什么会发生此错误??????????????? ????????????????????????????????????
【问题讨论】:
-
你能说明你想让你的程序做什么吗?
-
因为您的代码不是有问题的代码此代码陷入无限循环。
标签: c# string substring indexoutofboundsexception