
Looking at this syntax, it seems like it wouldn’t be possible to use in scenarios where you need to pass in the string from an external source, such a localization table or resource dictionary. Consider this string:ĭim requestUrl = $" This is actually a bug. Just as with String.Format, which is used by this syntax, one still has to watch out for contextual escaping. Here is a basic example using the variables name and total, the latter being formatted as currency.ĭim message = $"Hello " And like String.Format, you can include formatting options. Each position where you want to insert a value is escaped in braces in the same way String.Format would be. Interpolated strings begin with $" instead of just ". String interpolation, a technique first demonstrated in C# by the Mono team, finally ends that practice. Mistakes in the count have probably led to countless bugs over the years. String.Format has had developers counting parameters since. Since the NameOf operator creates constants you can use it wherever you would use a hard-coded string.

This eliminates the possibility of renaming the parameter without remembering to change the string in the exception constructor. If name is Nothing Then Throw New ArgumentNullException(NameOf(name)) The first example offered by Lucian Wischik of the Visual Basic team involves parameter validation.įunction Lookup(name As String) As Customer For these other cases, the NameOf operator comes into play.

While this solved the property change notification problem, it wasn’t general enough for other cases where an identifier needed to be expressed as a string.


In Visual Basic 12, we saw the introduction of the CallerNameAttribute. Others hate that they don’t get null reference exceptions and instead the method silently fails, leaving them confused as to why there is a null where they were expecting it. Some developers love that they don’t have to worry about null reference exceptions when performing method invocations. In the Objective-C community, this feature has a mixed reputation. Specifically, method invocations using the dot operator works like VB’s ?. Objective-C, well known for its use in Apple products, has this behavior by default. The If operator can be combined with this to supply a default value:ĭim numberOfCarPorts = If(property.PrimaryResidence?.Garage?.Cars, 0)Ĭ# and VB are not the only languages that have null handling like this.
