I read boxing and string.format(). And I found out that he will enter a value type, for example an integer.
So the following code will cause boxing
var number = 5;
var sampleString = string.Format("The number 5: {0}", number);
This code will result in a line
The number 5: 5
However, if I concatenate using the standard operator +, it still produces the same string.
var sampleString = "The number 5: " + number;
What is happening here, is it also transforming the whole into an object?
This also works with a date object, e.g.
var dateString = string.Format("The date: {0}", DateTime.Now);
var dateString = "The date: " + DateTime.Now;
I assume the first line will be a field, but the second line will not be?
source
share