सभी स्वरों की जाँच करने के लिए, सबसे पहले जाँच करने के लिए शर्त सेट करें -
string res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();
ऊपर, हमने स्ट्रिंग का उपयोग किया है -
string str = "the quick brown fox jumps over the lazy dog";
अब, Any() विधि का उपयोग करके जांचता है कि स्ट्रिंग में कोई स्वर है या नहीं -
if(!res.Any())
Console.WriteLine("No vowels!"); स्वर प्राप्त करने के लिए स्ट्रिंग के माध्यम से लूप करें -
उदाहरण
using System;
using System.Linq;
public class Program {
public static void Main() {
string str = "the quick brown fox jumps over the lazy dog";
var res = str.Where(chk =< "aeiouAEIOU".Contains(chk)).Distinct();
if(!res.Any())
Console.WriteLine("No vowels!");
foreach(var vowel in res)
Console.WriteLine("Your phrase contains vowel = {0}", vowel);
}
} आउटपुट
Your phrase contains vowel = e Your phrase contains vowel = u Your phrase contains vowel = i Your phrase contains vowel = o Your phrase contains vowel = a