c# - 嵌入语句错误

标签 c#

这是我的代码:

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

iPlay.Play();

这里是错误:

嵌入语句不能是声明或标记语句

如果那不可能,介意告诉我怎么做吗?

最佳答案

iPlay.Play(); 超出了 if-else 语句中的 else 子句的范围。尝试用大括号将其括起来以用于多行范围。

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

关于c# - 嵌入语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12469177/

相关文章:

c# - Tablets.Count 方法中的 ArgumentException

c# - Gremlin.net textContains 等效项

c# - Umbraco通过代码创建内容导致缓存失效

.net 2.0 附带的c# 版本号?

c# - 从linq中的第n条记录中选择n条记录

c# - 是否有 Jeff Atwood 的 C#/Winforms .Net 3.5+ 的用户友好异常处理(或类似的)?

c# - Linq SelectMany 查询

c# - Plesk Linux ASP.NET Core ERR_CONNECTION_REFUSED

c# - 在postgresql中添加到bytea blob的函数

c# - 如何停止非响应线程