Choices.Add Yöntem

Tanım

Alternatifler kümesine öğe ekler.

Aşırı Yüklemeler

Name Description
Add(GrammarBuilder[])

Alternatifler kümesine bir veya daha fazla GrammarBuilder nesne içeren bir dizi ekler.

Add(String[])

Alternatifler kümesine bir veya daha fazla String nesne içeren bir dizi ekler.

Add(GrammarBuilder[])

Kaynak:
Choices.cs
Kaynak:
Choices.cs
Kaynak:
Choices.cs
Kaynak:
Choices.cs

Alternatifler kümesine bir veya daha fazla GrammarBuilder nesne içeren bir dizi ekler.

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

Parametreler

alternateChoices
GrammarBuilder[]

GrammarBuilder Bu Choices nesneye eklenecek nesneler.

Örnekler

Aşağıdaki örnek, "Cep telefonunda Anne'i ara" ve "İş telefonunda James'i ara" gibi ifadeler için bir konuşma tanıma dil bilgisi oluşturur. Örnek, dil bilgisini oluşturmak için yönteminin Add her iki aşırı yüklemesini de kullanır.

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

Açıklamalar

, ve Choices nesnelerinden SemanticResultKeySemanticResultValueGrammarBuilderöğesine örtük dönüştürme desteği nedeniyle, bu üç sınıf da bir Choices örneğe eklenebilir.

Boş bir diziyse alternateChoices , bu yöntem alternatifler kümesini güncelleştirmez.

Uygulamalar bir nesneye alternatifler Add(String[]) eklemek için hem Add(GrammarBuilder[]) hem de Choices kullanabilir.

Bu yöntem olduğunda ArgumentNullExceptionalternateChoices veya dizi öğelerinden herhangi biri olduğunda nulloluştururnull.

Ayrıca bkz.

Şunlara uygulanır

Add(String[])

Kaynak:
Choices.cs
Kaynak:
Choices.cs
Kaynak:
Choices.cs
Kaynak:
Choices.cs

Alternatifler kümesine bir veya daha fazla String nesne içeren bir dizi ekler.

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

Parametreler

phrases
String[]

Bu Choices nesneye eklenecek dizeler.

Örnekler

Aşağıdaki örnek, "Cep telefonunda Anne'i ara" ve "İş telefonunda James'i ara" gibi ifadeler için bir konuşma tanıma dil bilgisi oluşturur. Örnek, dil bilgisini oluşturmak için yönteminin Add her iki aşırı yüklemesini de kullanır.

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

Açıklamalar

Uygulamalar bir nesneye alternatifler Add(String[]) eklemek için hem Add(GrammarBuilder[]) hem de Choices kullanabilir.

Boş bir diziyse phrases , bu yöntem alternatifler kümesini güncelleştirmez.

Bu yöntem olduğunda ArgumentNullExceptionphrases veya dizi öğelerinden herhangi biri olduğunda nulloluştururnull. Bu yöntem dizideki herhangi bir öğe boş dize ("") ise bir ArgumentException oluşturur.

Ayrıca bkz.

Şunlara uygulanır