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.
Student
I am Utpal Vishwas from Uttar Pradesh. Have completed my B. Tech. course from MNNIT campus Prayagraj in 2022. I have good knowledge of computer networking.
Sure, 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.