Write a function to count the number of vowels in a given string.
Write a function to count the number of vowels in a given string.
228
14-Jun-2023
Aryan Kumar
15-Jun-2023Sure, here is the C# code to write a function to count the number of vowels in a given string:
C#
This function first creates a variable called vowelCount and initializes it to 0. Then, it iterates through all the characters in the string. For each character, the function checks if the character is a vowel. If it is, then the function increments the value of vowelCount by 1. Finally, the function returns the value of vowelCount. The Main() method then calls the CountVowels() function to count the number of vowels in the string. The result is then printed to the console.