I'm trying to create a process to count the frequency of each letter in a given input string. The code I have so far seems to work fine, except for updating the value of the int at a given index in the int array. When I debug the code it is successfully finding the index of the string array which corresponds to the character of the moment, so it appears that the problem is with the line: alphabetCount[index] = alphabetCount[index]++;
Here is the code.
string[] alphabet = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
int[] alphabetCount = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
string baseInput = string.Empty;
private void button_count1_Click(object sender, EventArgs e)
{
baseInput = textBox_base.Text.ToUpper();
int length = baseInput.Length;
for (int i = 0; i < length; i++)
{
try
{
int index = Array.IndexOf(alphabet,baseInput[i].ToString());
alphabetCount[index] = alphabetCount[index]++;
}
catch
{
//MessageBox.Show("nope");
}
}
}