Memory usage of concatenating strings using interpolated vs "+" operator

harveyAJ picture harveyAJ · Feb 21, 2017 · Viewed 18.6k times · Source

I see the benefit of using interpolated strings, in terms of readability:

string myString = $"Hello { person.FirstName } { person.LastName }!"

over a concatenation done this way:

string myString = "Hello " + person.FirstName + " " person.LastName + "!";

The author of this video tutorial claims that the first one makes better use of memory.

How come?

Answer

Servy picture Servy · Feb 21, 2017

The author doesn't actually say that one makes better use of memory than the other. It says that the one method "makes good use of memory" in the abstract, which, by itself, doesn't really mean much of anything.

But regardless of what they said, the two methods aren't going to be meaningfully different in their implementation. Neither is going to be meaningfully different from the other in terms of memory or time.