I have this error
"Cannot assign method group to an implicitly-typed local variable"
in this code
private async void Button_Click_2(object sender, RoutedEventArgs e) { var frenchvoice = InstalledVoices.All.Where(voice => voice.Language.Equals("fr-FR") & voice.Gender == VoiceGender.Female).FirstOrDefault; // in this line sp.SetVoice(frenchvoice); await sp.SpeakTextAsync(mytxt); }
You forgot to call the function (with ()
)
You must add the round brackets to call the method FirstOrDefault
var frenchvoice = InstalledVoices.All .Where(voice => voice.Language.Equals("fr-FR") && voice.Gender == VoiceGender.Female) .FirstOrDefault();
And, while your code works also using the & operator, the correct one to use in a logical condition is &&
By the way, FirstOrDefault
accepts the same lambda applied to Where so you could reduce your code to a simpler and probably faster
var frenchvoice = InstalledVoices.All .FirstOrDefault(voice => voice.Language.Equals("fr-FR") && voice.Gender == VoiceGender.Female);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With