Shortcut Formatting: A feature request for C# vNext!
10 01 2008I’ve been pondering what possible features could be added to C# after version 3.5 of the compiler. For sure things like parallelism constructs are on the radar for the language team at Microsoft, but while they are at it I would like them to tackle a simpler challenge as well - a shortcut for formatting strings.
Let’s say that my code is going to throw and exception, I typically need to build the error message to load into the exception message. That could be expressed as:
throw new Exception(string.Format(”{0}{1}{2}”, a, b, c));
But I think we could have a nicer inline string format syntax:
throw new Exception( @(”{0}{1}{2}”|a|b|c) );
I’m not sure about the syntax, but the idea is a more compact syntax that would look good inline, especially if you had nested object constructions, like a LINQ projection.
Comments : 9 Comments »
Categories : Uncategorized



Recent Comments