Choices.Add 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
新增選項。
多載
| 名稱 | Description |
|---|---|
| Add(GrammarBuilder[]) |
將包含一個或多個 GrammarBuilder 物件的陣列加入選項集合。 |
| Add(String[]) |
將包含一個或多個 String 物件的陣列加入選項集合。 |
Add(GrammarBuilder[])
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
將包含一個或多個 GrammarBuilder 物件的陣列加入選項集合。
public:
void Add(... cli::array <System::Speech::Recognition::GrammarBuilder ^> ^ alternateChoices);
public void Add(params System.Speech.Recognition.GrammarBuilder[] alternateChoices);
member this.Add : System.Speech.Recognition.GrammarBuilder[] -> unit
Public Sub Add (ParamArray alternateChoices As GrammarBuilder())
參數
- alternateChoices
- GrammarBuilder[]
GrammarBuilder要加入這個Choices物件的物件。
範例
以下範例為「Call Anne on her cell」和「Call James on his work phone」等片語建立語音辨識文法。 範例中同時使用方法的超載 Add 來建立文法。
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
備註
由於支援從 Choices、 SemanticResultKey以及 SemanticResultValue 物件 到 GrammarBuilder的隱式轉換,這三個類別也可以加入到一個 Choices 實例中。
若 alternateChoices 為空陣列,此方法不會更新備選集合。
應用程式可以同時使用 Add(String[]) 兩者,並 Add(GrammarBuilder[]) 對物件添加替代方案 Choices 。
此方法拋出 當 ArgumentNullExceptionalternateChoices 是 或 null 任一陣列元素 時 null。
另請參閱
適用於
Add(String[])
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
- 來源:
- Choices.cs
將包含一個或多個 String 物件的陣列加入選項集合。
public:
void Add(... cli::array <System::String ^> ^ phrases);
public void Add(params string[] phrases);
member this.Add : string[] -> unit
Public Sub Add (ParamArray phrases As String())
參數
範例
以下範例為類似「Call Anne on her cell」和「Call James on his work phone」這類片語建立語音辨識文法。 範例中同時使用方法的超載 Add 來建立文法。
public Grammar CreatePhonePhrase()
{
// Create alternatives for female names and add a phrase.
GrammarBuilder females = new Choices(new string[] { "Anne", "Mary" });
females.Append("on her");
// Create alternatives for male names and add a phrase.
GrammarBuilder males = new Choices(new string[] { "James", "Sam" });
males.Append("on his");
// Create a Choices object that contains an array of alternative
// GrammarBuilder objects.
Choices people = new Choices();
people.Add(new Choices(new GrammarBuilder[] {females, males}));
// Create a Choices object that contains a set of alternative phone types.
Choices phoneType = new Choices();
phoneType.Add(new string[] { "cell", "home", "work" });
// Construct the phrase.
GrammarBuilder gb = new GrammarBuilder();
gb.Append("call");
gb.Append(people);
gb.Append(phoneType);
gb.Append(new GrammarBuilder("phone"), 0, 1);
return new Grammar(gb);
}
備註
應用程式可以同時使用 Add(String[]) 兩者,並 Add(GrammarBuilder[]) 對物件添加替代方案 Choices 。
若 phrases 為空陣列,此方法不會更新備用陣列集合。
此方法拋出 當 ArgumentNullExceptionphrases 是 或 null 任一陣列元素 時 null。 此方法若陣列中任一元素為空字串(“”),則拋出 。ArgumentException