If you searching for exact character then change the second paramater type to char:
public static int countLetters(string word, char countableLetter)
{
int count = 0;
foreach (char c in word)
{
if(countableLetter == c)
count++;
}
return count;
}
But you can do it with Count() method which included in System.Linq namespace:
return word.Count(x => x == countableLetter);
Additional:
If you want to find any char which contains in any string, then you can use:
public static int countLetters(string word, string countableLetters)
{
int count = 0;
foreach (char c in word)
{
if(countableLetters.Contains(c))
count++;
}
return count;
}
or with LINQ:
return word.Count(x => countableLetters.Contains(x));