Mono Introduces Experimental C# Language Extensions

| by Jonathan Allen Follow 491 Followers on Dec 28, 2009. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

Having caught with the recent advances in Microsoft’s C# 4, the Mono team is now playing with their own extensions to the language. The two features they are experimenting with are string interpolation and support for multiple return values.

String interpolation is essentially a shortcut for the String.Format syntax. Instead of explicitly calling that function with a string containing numeric placeholders, the string is constructed using expressions in the placeholders. For example,

var a = 'Hello {name} how are you?';

Note that in this example from Miguel de Icaza, the string is detonated by single quotes instead of double-quotes. Miguel is currently soliciting feedback on this feature from Python and Ruby users, as he expects them to be more familiar with any potential problems.

The second language extension is support for tuples, also known as multiple return values. Given a function that returns a tuple, his patch would allow the function to be called and the tuple unpacked in the same line.

Tuple<string, string, string, int, string> ParseUri (string url);
(user, password, host, port, path) = ParseUri (url);

Creating and returning a tuple would look just like the assignment syntax. Miguel is also considering extending this to support slicing arrays, enumerations, and older forms of tuple such as DictionaryEntry.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

the real value is in pattern matching by Morgan Creighton

The real value of multiple return values comes from pattern matching, as it does in a language like Scala. I really want to be able to pattern match on the values returned, not just their types, so I can write expressive code like...

(true, response) = someFunctionThatMightFail()

Hopefully, this sort of thing is considered when introducing tuples to Mono.

Anders Hejlsberg take note for c# 5.0 by Binoj Antony

Always wanted the multiple return value feature from c#, Anders Hejlsberg should take note of this and think of implementing it in c# 5.0

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss

Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you