I'm making a letter counter in c#, it compiles ok, but whenever I run it, I have this error "System.IndexOutOfRangeException" on line "if(chars[num]==knizka[num1])". What should I do please? idk why i need to add more text
int num = 0;
int num1 = 0;
string knihaRef = System.IO.File.ReadAllText("Osnova.txt");
knihaRef = knihaRef.ToLower();
string abcd ="abcdefghijklmnopqrstuvwxyz";
abcd = abcd.ToLower();
char[] chars =abcd.ToArray();
char[] knizka = knihaRef.ToArray();
int[] numOfLet =new int[26];
for (int i=0; i<chars.Length;i++)
{
numOfLet[i] = 0;
}
while(num1<knizka.Length)
{
if (chars[num]==knizka[num1])
{
numOfLet[num]++;
num1++;
num++;
if (num>=numOfLet.Length)
{
num = 0;
}
}
else
{
num++;
}
}