BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Mono Introduces Experimental C# Language Extensions

Mono Introduces Experimental C# Language Extensions

This item in japanese

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
Style

BT