You are searching twice for "A"
for (int n = 0; n < 25; n++)
{
for (int i = 0; i < s.Length; i++)
{
if (s[i] == c)
count++;
}
label1.Text = "Letter" + c + " occured " + count.ToString() + " times";
int l = (int)c + n;
c = (char)l;
}
char[] s = new char[50];
string t = textBox1.Text;
for (int j = 0; j < t.Length; j++)
s[j] = t[j];
Try something like this:
static int foo(string source, char charToCount)
{
int occurences = 0;
for (int i = 0; i < source.Length; i++)
{
if (source[i] == charToCount)
occurences++;
}
return occurences;
}
It's like solution 1 without Linq
Disadvantage of both solutions is, that you have to parse the whole string for every letter.