TwiML (Twilio Markup Language) can be generated using strongly-typed C# classes. You can create elements standalone, set attributes directly, or use helper methods on a VoiceResponse object to append elements. The resulting object can be serialized to an XML string.
// TwiML classes can be created as standalone elements
var gather = new Gather(numDigits: 1, action: new Uri("hello-monkey-handle-key.cshtml"), method: HttpMethod.Post)
.Say("To speak to a real monkey, press 1. Press 2 to record your own monkey howl. Press any other key to start over.");
// Attributes can be set directly on the object
gather.Timeout = 100;
gather.MaxSpeechTime = 200
// Arbitrary attributes can be set by calling set/getOption
var dial = new Dial().SetOption("myAttribute", 200)
.SetOption("newAttribute", false);
// Or can be created and attached to a response directly using helper methods
var response = new VoiceResponse()
.Say("Hello Monkey")
.Play(new Uri("http://demo.twilio.com/hellomonkey/monkey.mp3"))
.Append(gather)
.Append(dial);
// Serialize the TwiML objects to XML string
Console.WriteLine(response);