共用方式為


SrgsOneOf.Add(SrgsItem) 方法

定義

將包含單字或片語的SrgsItem加入至替代選項清單中。

public:
 void Add(System::Speech::Recognition::SrgsGrammar::SrgsItem ^ item);
public void Add (System.Speech.Recognition.SrgsGrammar.SrgsItem item);
member this.Add : System.Speech.Recognition.SrgsGrammar.SrgsItem -> unit
Public Sub Add (item As SrgsItem)

參數

item
SrgsItem

要加入至替代項目清單的項目。

例外狀況

itemnull

範例

下列範例會建立一個文法,可辨識「已贏得 World Cup 的一名國家/地區」片語,後面接著贏得 World Cup 的國家/地區名稱。 此範例會 SrgsOneOf 使用 物件,從 物件的陣列 SrgsItem 建置可接受的國家/地區名稱清單。 範例會 Add 使用 方法,將包含字串 「義大利」 的 SrgsOneOf 附加 SrgsItem 至 物件 oneOfEurope

public void WorldSoccerWinners ()
{

  // Create an SrgsDocument, create a new rule
  // and set its scope to public.
  SrgsDocument document = new SrgsDocument();
  SrgsRule winnerRule = new SrgsRule("WorldCupWinner");
  winnerRule.Scope = SrgsRuleScope.Public;

  // Add the introduction.
  winnerRule.Elements.Add(new SrgsItem("A nation that has won the world cup is: "));

  // Create the rule for the European nations.
  SrgsOneOf oneOfEurope = new SrgsOneOf(new SrgsItem[] {new SrgsItem("England"),
    new SrgsItem("France"), new SrgsItem("Germany")});
  oneOfEurope.Add(new SrgsItem("Italy"));
  SrgsRule ruleEurope = (new SrgsRule("EuropeanNations", new SrgsElement[] {oneOfEurope}));

  // Create the rule for the South American nations.
  SrgsOneOf oneOfSAmerica = new SrgsOneOf(new SrgsItem[] {new SrgsItem("Argentina"),
    new SrgsItem("Brazil"), new SrgsItem("Uruguay")});
  SrgsRule ruleSAmerica = (new SrgsRule("SouthAmericanNations", new SrgsElement[] {oneOfSAmerica}));

  // Add references to winnerRule for ruleEurope and ruleSAmerica.
  winnerRule.Elements.Add(new SrgsOneOf(new SrgsItem[] {(new SrgsItem
    (new SrgsRuleRef(ruleEurope))), new SrgsItem(new SrgsRuleRef(ruleSAmerica))}));

  // Add all the rules to the document and make winnerRule
  // the root rule of the document.
  document.Rules.Add(new SrgsRule[] {winnerRule, ruleEurope, ruleSAmerica});
  document.Root = winnerRule;
}

適用於

另請參閱