c# - When is it better to use String.Format vs string concatenation? -
i've got small piece of code parsing index value determine cell input excel. it's got me thinking...
what's difference between
xlssheet.write("c" + rowindex.tostring(), null, title);
and
xlssheet.write(string.format("c{0}", rowindex), null, title);
is 1 "better" other? , why?
before c# 6
to honest, think first version simpler - although i'd simplify to:
xlssheet.write("c" + rowindex, null, title);
i suspect other answers may talk performance hit, honest it'll minimal if present @ all - , concatenation version doesn't need parse format string.
format strings great purposes of localisation etc, in case concatenation simpler , works well.
with c# 6
string interpolation makes lot of things simpler read in c# 6. in case, second code becomes:
xlssheet.write($"c{rowindex}", null, title);
which best option, imo.
Comments
Post a Comment