SpeechRecognitionEngine.Grammars 属性

定义

获取在此 Grammar 实例中加载的 SpeechRecognitionEngine 对象的集合。

public:
 property System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::Grammar ^> ^ Grammars { System::Collections::ObjectModel::ReadOnlyCollection<System::Speech::Recognition::Grammar ^> ^ get(); };
public System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.Grammar> Grammars { get; }
member this.Grammars : System.Collections.ObjectModel.ReadOnlyCollection<System.Speech.Recognition.Grammar>
Public ReadOnly Property Grammars As ReadOnlyCollection(Of Grammar)

属性值

ReadOnlyCollection<Grammar>

Grammar 对象的集合。

示例

下面的示例将语音识别器当前加载的每个语音识别语法的信息输出到控制台。

重要

如果在此方法枚举集合中的元素时修改了集合,则复制语法集合以避免出现错误。

private static void ListGrammars(SpeechRecognitionEngine recognizer)  
{  
  string qualifier;  
  List<Grammar> grammars = new List<Grammar>(recognizer.Grammars);  
  foreach (Grammar g in grammars)  
  {  
    qualifier = (g.Enabled) ? "enabled" : "disabled";  

    Console.WriteLine("Grammar {0} is loaded and is {1}.",  
      g.Name, qualifier);  
  }  
}  

适用于

另请参阅