Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Swift: xCode Exercise Concatenation and Interpolation Create a city constant and

ID: 3754788 • Letter: S

Question

Swift: xCode

Exercise Concatenation and Interpolation Create a city constant and assign it a string literal representing your home city. Then create a state constant and assign it a string literal representing your home state. Finally, create a home constant and use string concatenation to assign it a string representing your home city and state (i.e. Portland, Oregon). Print the value of home. Use the compound assignment operator (+) to add home to introduction below. Print the value of introduction. 11 var introduction "I live in" 12 13 Declare a name constant and assign it your name as a string literal. Then declare an age constant and give it your current age as an Int. Then print the following phrase using string interpolation My name is and after my next birthday I will be years old." Insert name where indicated, and insert a mathematical expression that evaluates to your current age plus one where indicated.

Explanation / Answer

public class StringConcatVsStringInterpolation { private string data1; private string data2; private string data3; public StringConcatVsStringInterpolation() { data1 = Guid.NewGuid().ToString(); data2 = Guid.NewGuid().ToString(); data3 = Guid.NewGuid().ToString(); } [Benchmark] public string StringConcat() => "test format" + data1 + data2 + data3; [Benchmark] public string StringInterpolation() => ($"test format{data1}, {data2}, {data3}"); }