This function counts how often letter occur in a given string and puts that in an array (index is ascii-number of letter and value ist counted occurrences). Now I need to return both the letter (which it already does) and the value. Just by reading online I couldn't figure out how to use ref and alternatives to do that.
static char MostCommonLetter(string s)
{
int[] occurrances = new int[255];
for (int i = 0; i < s.Length; i++)
{
if (char.IsLetter(s[i]))
{
int ascii = (int)s[i];
occurrances[ascii]++;
}
}
char maxValue = (char)Array.IndexOf(occurrances, occurrances.Max());
return maxValue;
}