String Interpolation with format variable

后端 未结 6 1993
心在旅途
心在旅途 2020-11-27 22:08

I can do this:

var log = string.Format(\"URL: {0}\", url);

or even like this

var format = \"URL: {0}\";
...
var log = strin         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 22:58

    This is supposed to be a comment to the answer from i3arnon but I do not have the reputation :-( : But for those who come to this old thread, in string.Format the format can be a variable:

    string name = "bar";
    string format = "{0}";
    string result = string.Format(format, name);
    

    works.

提交回复
热议问题