GrammarBuilder.Implicit 运算符  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将另一种类型为 GrammarBuilder。
重载
注解
隐式转换创建的一个新实例 GrammarBuilder 。 可以将以下每个类强制转换为 GrammarBuilder 。
每个隐式强制转换等效于调用构造函数。
Implicit(Choices to GrammarBuilder)
将 Choices 对象转换为 GrammarBuilder 对象。
public:
 static operator System::Speech::Recognition::GrammarBuilder ^(System::Speech::Recognition::Choices ^ choices);public static implicit operator System.Speech.Recognition.GrammarBuilder (System.Speech.Recognition.Choices choices);static member op_Implicit : System.Speech.Recognition.Choices -> System.Speech.Recognition.GrammarBuilderPublic Shared Widening Operator CType (choices As Choices) As GrammarBuilder参数
- choices
- Choices
要转换的替代组。
返回
转换的 Choices 对象。
示例
下面的示例创建一个语音识别语法,它可以识别对 "是" 或 "否" 问题的响应。 隐式转换运算符用于 SemanticResultValue 从对象构造对象 Choices 、 Choices 从两个对象构造对象 SemanticResultValue ,以及在对象的构造 Grammar 对象 SemanticResultKey 中构造对象。
Choices yesChoices = new Choices(new string[] {"yes", "yup", "yah"});  
SemanticResultValue yesValue =  
  new SemanticResultValue(yesChoices, true);  
Choices noChoices = new Choices(new string[] { "no", "nope", "nah" });  
SemanticResultValue noValue =  
  new SemanticResultValue(noChoices, false);  
SemanticResultKey yesnoKey =  
  new SemanticResultKey("yesno", new Choices(new GrammarBuilder[] { yesValue, noValue }));  
Grammar yesnoGrammar = new Grammar(yesnoKey);  
yesnoGrammar.Name = "yesno";  
注解
隐式转换创建的一个新实例 GrammarBuilder 。 此转换运算符等效于调用 GrammarBuilder 并为指定 choices alternateChoices 。
此运算符的等效方法是 GrammarBuilder.GrammarBuilder(Choices)
另请参阅
适用于
Implicit(SemanticResultKey to GrammarBuilder)
将 SemanticResultKey 对象转换为 GrammarBuilder 对象。
public:
 static operator System::Speech::Recognition::GrammarBuilder ^(System::Speech::Recognition::SemanticResultKey ^ semanticKey);public static implicit operator System.Speech.Recognition.GrammarBuilder (System.Speech.Recognition.SemanticResultKey semanticKey);static member op_Implicit : System.Speech.Recognition.SemanticResultKey -> System.Speech.Recognition.GrammarBuilderPublic Shared Widening Operator CType (semanticKey As SemanticResultKey) As GrammarBuilder参数
- semanticKey
- SemanticResultKey
要转换的语义键。
返回
转换的 SemanticResultKey 对象。
示例
下面的示例创建一个语音识别语法,它可以识别对 "是" 或 "否" 问题的响应。 隐式转换运算符用于 SemanticResultValue 从对象构造对象 Choices 、 Choices 从两个对象构造对象 SemanticResultValue ,以及在对象的构造 Grammar 对象 SemanticResultKey 中构造对象。
Choices yesChoices = new Choices(new string[] {"yes", "yup", "yah"});  
SemanticResultValue yesValue =  
  new SemanticResultValue(yesChoices, true);  
Choices noChoices = new Choices(new string[] { "no", "nope", "nah" });  
SemanticResultValue noValue =  
  new SemanticResultValue(noChoices, false);  
SemanticResultKey yesnoKey =  
  new SemanticResultKey("yesno", new Choices(new GrammarBuilder[] { yesValue, noValue }));  
Grammar yesnoGrammar = new Grammar(yesnoKey);  
yesnoGrammar.Name = "yesno";  
注解
隐式转换创建的一个新实例 GrammarBuilder 。 此转换运算符等效于调用 GrammarBuilder 并为指定 semanticKey key 。
此运算符的等效方法是 GrammarBuilder.GrammarBuilder(SemanticResultKey)
另请参阅
适用于
Implicit(SemanticResultValue to GrammarBuilder)
将 SemanticResultValue 对象转换为 GrammarBuilder 对象。
public:
 static operator System::Speech::Recognition::GrammarBuilder ^(System::Speech::Recognition::SemanticResultValue ^ semanticValue);public static implicit operator System.Speech.Recognition.GrammarBuilder (System.Speech.Recognition.SemanticResultValue semanticValue);static member op_Implicit : System.Speech.Recognition.SemanticResultValue -> System.Speech.Recognition.GrammarBuilderPublic Shared Widening Operator CType (semanticValue As SemanticResultValue) As GrammarBuilder参数
- semanticValue
- SemanticResultValue
要转换的 SemanticResultValue 对象。
返回
转换的 SemanticResultValue 对象。
示例
下面的示例创建一个语音识别语法,它可以识别对 "是" 或 "否" 问题的响应。 隐式转换运算符用于 SemanticResultValue 从对象构造对象 Choices 、 Choices 从两个对象构造对象 SemanticResultValue ,以及在对象的构造 Grammar 对象 SemanticResultKey 中构造对象。
Choices yesChoices = new Choices(new string[] {"yes", "yup", "yah"});  
SemanticResultValue yesValue =  
  new SemanticResultValue(yesChoices, true);  
Choices noChoices = new Choices(new string[] { "no", "nope", "nah" });  
SemanticResultValue noValue =  
  new SemanticResultValue(noChoices, false);  
SemanticResultKey yesnoKey =  
  new SemanticResultKey("yesno", new Choices(new GrammarBuilder[] { yesValue, noValue }));  
Grammar yesnoGrammar = new Grammar(yesnoKey);  
yesnoGrammar.Name = "yesno";  
注解
隐式转换创建的一个新实例 GrammarBuilder 。 此转换运算符等效于调用 GrammarBuilder 并为指定 semanticValue value 。
此运算符的等效方法是 GrammarBuilder.GrammarBuilder(SemanticResultValue)
另请参阅
适用于
Implicit(String to GrammarBuilder)
将字符串转换为 GrammarBuilder 对象。
public:
 static operator System::Speech::Recognition::GrammarBuilder ^(System::String ^ phrase);public static implicit operator System.Speech.Recognition.GrammarBuilder (string phrase);static member op_Implicit : string -> System.Speech.Recognition.GrammarBuilderPublic Shared Widening Operator CType (phrase As String) As GrammarBuilder参数
- phrase
- String
要转换的字符串。
返回
已转换的字符串。
示例
下面的示例使用 GrammarBuilder 和 Choices 对象来构造语法,该语法可识别两个短语中的任意一个: "使背景 colorChoice" 或 "将背景设置为 colorChoice"。
使用对象为 colorChoice 创建可接受的值列表后 Choices ,该示例将 GrammarBuilder makePhrase setPhrase 使用字符串对象的隐式转换初始化两个对象。
该示例最终 Grammar 从 Choices 对象强制转换为对象创建对象 GrammarBuilder 。
private Grammar CreateColorGrammar()  
{  
  // Create a set of color choices.  
  Choices colorChoice = new Choices(new string[] {"red", "green", "blue"});  
  GrammarBuilder colorElement = new GrammarBuilder(colorChoice);  
  // Create grammar builders for the two versions of the phrase.  
  GrammarBuilder makePhrase = new GrammarBuilder("Make background");  
  makePhrase.Append(colorElement);  
  GrammarBuilder setPhrase = new GrammarBuilder("Set background to");  
  setPhrase.Append(colorElement);  
  // Create a Choices for the two alternative phrases, convert the Choices  
  // to a GrammarBuilder, and construct the Grammar object from the result.  
  Choices bothChoices = new Choices(new GrammarBuilder[] {makePhrase, setPhrase});  
  Grammar grammar = new Grammar((GrammarBuilder)bothChoices);  
  grammar.Name = "backgroundColor";  
  return grammar;  
}  
注解
隐式转换创建的一个新实例 GrammarBuilder 。 此转换运算符等效于调用 GrammarBuilder 并指定相同的 phrase 。
此运算符的等效方法是 GrammarBuilder.GrammarBuilder(String)