I m curious why would i use string formatting while i can use concatenation such as
Console.WriteLine("Hello {0} !", name);
Console.WriteLine("Hello "+ name + " !");
Why to prefer the first one over second?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You picked too simple of an example.
String formatting:
("{0} + {0} = {1}", x, 2*x)ToStringon its arguments:("{0}: {1}", someKeyObj, someValueObj)("The value will be {0:3N} (or {1:P}) on {2:MMMM yyyy gg}", x, y, theDate)(">{0,3}<", "hi"); // ">hi <"