Troolean-type values
本文关键字:values Troolean-type | 更新日期: 2023-09-27 18:16:41
我的应用程序中有一个演讲类,希望能够看到它是在听,录音,口述还是无响应;
我想要的是能够做的是分配某种变量(SpeechState)只是3个可能值中的1个,并检查它,像这样:
startListeningButton_Click(object sender, EventArgs e)
{
SpeechState = SpeechState.Listening;
}
stopListeningButton_Click(object sender, EventArgs e)
{
if(SpeechState.Listening)
{
// Code to STOP listening goes here.
}
}
我试过实现troolean,但那不是我真正想要的。我在之后的类似于以下内容:
if(checkBox1.CheckState == CheckState.Checked)
{
// Do something
}
我怎样才能做到这一点?
你应该为它创建一个enum
public enum SpeechState
{
Listening,
Recording,
Dictating,
Unresponsive
}
您可以完全按照您所展示的设置来使用它,尽管检查将是:
if(this.SpeechState == SpeechState.Listening)
回复评论编辑:
为了把它放在你的类中,你需要一个属性来存储它:
public class YourClass
{
public SpeechState SpeechState { get; set; }
}
使用枚举:
public enum SpeechState
{
Listening,
Recording,
Dictating,
Unresponsive
}