C# - 比较2个数组中的值

Isu*_*uru 1 c# arrays

我想做的事情很简单.用户输入一个字符串.该程序检查并计算该文本字符串中存在的元音数量.

    char[] vowels = {'a', 'e', 'i', 'o', 'u'};
    int counter = 0;

    string s = txtInput.Text.Trim();
    char[] arr = s.ToCharArray();


    foreach (char i in arr)
    {
        //checks the 2 arrays for matches
        counter++;
    }
Run Code Online (Sandbox Code Playgroud)

如何检查2个数组以查看是否有匹配?

谢谢.

dar*_*yal 6

arr.Any(p => vowels.Contains(p));
Run Code Online (Sandbox Code Playgroud)

更新:计算您可能使用的匹配数量;

 int count = arr.Where(p => vowels.Contains(p)).Count();
Run Code Online (Sandbox Code Playgroud)