我对C#还是很陌生,但是大多数时候我都可以处理以自己的方式抛出的错误,但这似乎不起作用。不知道我是否太接近问题或其他问题。
-问题-
我一直在从事一个名为“SoundBoard For Kids”的小项目,在该项目中,我想创建一个教育软件,例如一本Sound book,没有什么花哨的东西只是为了使我的知识发扬光大,而且我已经在代码中做了很多但是现在当我尝试使按钮播放声音时,我无法使代码正常工作,“Dim”语句不想点亮,“As String”也不能点亮。我是否忘记添加某些内容?我担心添加媒体播放器,因为我担心它会弄乱整个代码。
private void button1_Click(object sender, EventArgs e)
{
Dim sPath As String
Dim mySound As Media.SoundPlayer
sPath = "Location of where I have the sound file.wmv"
mySound = new Media.SoundPlayer(sPath)
mySOund.Play()
}
最佳答案
由于您未提供错误代码,因此我认为这是语法错误。
您的button_click事件应类似于以下内容:
private void button1_Click(object sender, EventArgs e)
{
string sPath; //Declaration pattern: Variable Type followed by Name
System.Media.SoundPlayer mySound; //if you're not using namespace full path
sPath = "Location of where I have the sound file.wmv";
mySound = new Media.SoundPlayer(sPath);
mySOund.Play();
}
由于dim在VB中使用,在C#中不存在。您应该如上所述声明变量。以下模式:类型,名称和可选-为变量提供值。
注意:应在使用之前分配引用类型,否则将抛出NullReferenceException。
关于c# - 在C#.NET Dim语句中创建共鸣板不会变成蓝色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33400795/