Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot assign method group to an implicitly-typed local variable

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); } 
like image 863
XXXX Avatar asked Oct 27 '13 20:10

XXXX


2 Answers

You forgot to call the function (with ())

like image 90
SLaks Avatar answered Sep 30 '22 05:09

SLaks


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); 
like image 28
Steve Avatar answered Sep 30 '22 03:09

Steve