c# - Why use {} for printing out instead of the plus sign? -


i coding in unity3d in c#, , when printing or using debug statements or console statements, have used this:

debug.log("the sum of these 2 variables :" + sumofvariables); 

however, going through new book try , learn better programmer, , use instead:

debug.log("the sum of these 2 variables {0}", sumofvariables); 

i assume doesnt matter either way, there advantage of using later? also, uses unity, getting error message when try use way, works fine when use first method. says debug.log doesnt have parameter that. , cant convert string expression type unityengine.object. variable using string property of class.

my question less unity peice , more better. credit if want tell me why error great. sure has been asked before, getting kinds of different topics when tried search, apologize in advance, answering!!

the reason why should use format strings instead of string concatenation because makes localization possible. it's easy translate format string different language, it's harder rewrite code.

"{0}: invalid photoscamp (id={1}) inside flange" 

in pig latin,

"{0}: invaliday otoscamphay (iday={1}) insidea angeflay" 

there other reasons use format strings, such performance, code readability, , ability store format strings in file or database. see c# string output: format or concat? , why use string.format?.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -