Click here to Skip to main content
15,891,423 members
Home / Discussions / C#
   

C#

 
QuestionString Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 3:59
professionalSascha Lefèvre20-Jan-16 3:59 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
Pete O'Hanlon20-Jan-16 4:19
mvePete O'Hanlon20-Jan-16 4:19 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 4:34
professionalSascha Lefèvre20-Jan-16 4:34 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Pete O'Hanlon20-Jan-16 4:46
mvePete O'Hanlon20-Jan-16 4:46 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 5:44
professionalSascha Lefèvre20-Jan-16 5:44 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Pete O'Hanlon20-Jan-16 6:53
mvePete O'Hanlon20-Jan-16 6:53 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 7:03
professionalSascha Lefèvre20-Jan-16 7:03 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
phil.o20-Jan-16 4:26
professionalphil.o20-Jan-16 4:26 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 4:36
professionalSascha Lefèvre20-Jan-16 4:36 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
PIEBALDconsult20-Jan-16 4:34
mvePIEBALDconsult20-Jan-16 4:34 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 5:41
professionalSascha Lefèvre20-Jan-16 5:41 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
PIEBALDconsult20-Jan-16 5:49
mvePIEBALDconsult20-Jan-16 5:49 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 5:55
professionalSascha Lefèvre20-Jan-16 5:55 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
PIEBALDconsult20-Jan-16 5:59
mvePIEBALDconsult20-Jan-16 5:59 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 7:43
professionalSascha Lefèvre20-Jan-16 7:43 
JokeRe: String Formatting / Interpolation --- Opinions Pin
Richard Deeming20-Jan-16 7:50
mveRichard Deeming20-Jan-16 7:50 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
Richard Deeming20-Jan-16 4:41
mveRichard Deeming20-Jan-16 4:41 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 5:38
professionalSascha Lefèvre20-Jan-16 5:38 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
BillWoodruff20-Jan-16 6:40
professionalBillWoodruff20-Jan-16 6:40 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre20-Jan-16 7:02
professionalSascha Lefèvre20-Jan-16 7:02 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
GravityPhazer21-Jan-16 23:53
professionalGravityPhazer21-Jan-16 23:53 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre22-Jan-16 1:59
professionalSascha Lefèvre22-Jan-16 1:59 
AnswerRe: String Formatting / Interpolation --- Opinions Pin
GravityPhazer22-Jan-16 4:11
professionalGravityPhazer22-Jan-16 4:11 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
Sascha Lefèvre22-Jan-16 4:29
professionalSascha Lefèvre22-Jan-16 4:29 
GeneralRe: String Formatting / Interpolation --- Opinions Pin
GravityPhazer22-Jan-16 4:37
professionalGravityPhazer22-Jan-16 4:37 
Well, I haven't ever thought about using anonymous classes for that.
I've written something that makes it easier (since I not only forget $ but also string.Format() at the beginning) by formatting at the end, like with your example. But using the same approach as the default format:
C#
var myString = "Test value 1 is {0} and value two is {1}".FormatWith(value1, value2);


The cool thing is that thanks to ReSharper you can tag that method as formatting method, and thus it highlights the placeholder braces if you use that method on a string. Pretty neat!
But using anonymous types for that is a nice idea, as well. I should implement that, too Smile | :)

PS: I should mention I implemented that method far before anonymous types were supported.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.