wolfgang ziegler


„make stuff and blog about it“

Non-Trivial Windows Phone Tasks in One Line of Code

January 12, 2014

I am a total sucker for one-liners when it comes to writing code.

Few things are more satisfying when writing code than being able to express a non-trivial intent as a one-line statement. It’s elegant, it’s concise and it’s little code - which means little room for error, right?

Fortunately, programming for Windows Phone offers a couple of chances to write some of these beautiful one-liners, when it comes to performing Tasks like sending email, calling phone numbers or opening web sites. Operations that seem complicated at first glance, boil down to very simple statements. Here are a few examples.

Opening a Web Site

new WebBrowserTask { Uri = new Uri("http://www.wolfgang-ziegler.com/") }.Show();

web

 

Sending Email

new EmailComposeTask
{
  To = "[email protected]",
  Subject = "Windows Phone ...",
  Body = "... rocks!"
}.Show();

email

 

Calling a Phone Number

new PhoneCallTask { PhoneNumber = "555 123" }.Show(); 

call