Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with embedded statements

Tags:

c#

This is my code:

if (RdoBtnBeepDefault.Checked) SystemSounds.Beep.Play();
else SoundPlayer iPlay = new SoundPlayer(@TxtBeepFile.Text);

iPlay.Play();

And here's the error:

Embedded statement cannot be a declaration or labeled statement

If that isn't possible, mind telling me how?

like image 253
user1667191 Avatar asked Sep 18 '12 01:09

user1667191


1 Answers

iPlay.Play(); is beyond the scope of your else clause in your if-else statement. Try enclosing it with braces for multiple line scope.

if (RdoBtnBeepDefault.Checked) 
{
    SystemSounds.Beep.Play();
)
else
{ 
    SoundPlayer iPlay = new SoundPlayer(TxtBeepFile.Text);
    iPlay.Play();
)
like image 91
John Woo Avatar answered Oct 04 '22 03:10

John Woo