Partilhar via


Choices.Add Method

Definition

Adds items to the set of alternatives.

Overloads

Add(GrammarBuilder[])

Adds an array containing one or more GrammarBuilder objects to the set of alternatives.

Add(String[])

Adds an array containing one or more String objects to the set of alternatives.

Add(GrammarBuilder[])

Source:
Choices.cs
Source:
Choices.cs
Source:
Choices.cs

Adds an array containing one or more GrammarBuilder objects to the set of alternatives.

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())

Parameters

alternateChoices
GrammarBuilder[]

The GrammarBuilder objects to add to this Choices object.

Examples

The following example creates a speech recognition grammar for phrases such as "Call Anne on her cell" and "Call James on his work phone". The example uses both overloads of the Add method to build the grammar.

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);  
}  

Remarks

Because of support for implicit conversion from Choices, SemanticResultKey, and SemanticResultValue objects to GrammarBuilder, these three classes may be added to a Choices instance as well.

If alternateChoices is an empty array, this method does not update the set of alternatives.

Applications can use both Add(String[]) and Add(GrammarBuilder[]) to add alternatives to a Choices object.

This method throws an ArgumentNullException when alternateChoices is null or any of the array elements are null.

See also

Applies to

Add(String[])

Source:
Choices.cs
Source:
Choices.cs
Source:
Choices.cs

Adds an array containing one or more String objects to the set of alternatives.

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())

Parameters

phrases
String[]

The strings to add to this Choices object.

Examples

The following example creates a speech recognition grammar for phrases similar to "Call Anne on her cell" and "Call James on his work phone". The example uses both overloads of the Add method to build the grammar.

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);  
}  

Remarks

Applications can use both Add(String[]) and Add(GrammarBuilder[]) to add alternatives to a Choices object.

If phrases is an empty array, this method does not update the set of alternates.

This method throws an ArgumentNullException when phrases is null or any of the array elements are null. This method throws an ArgumentException if any element in the array is the empty string ("").

See also

Applies to