varx=1;
// same as string.Format("A {0} B", x) vary1=$"A {x} B"; // y == "A 1 B"// $@ for multilinevary2=$@"A{x}B";
// Formattingvary3=$"A {1.23:F1} B"; // y == "A 1.2 B"
Operator ?.
// same as (person != null ? person.Name : null)varname1=person?.Name;
// same as (person != null ? person.Name : "(Unknown)")varname2=person?.Name??"(Unknown)";
// methods (same as Sum(int a, int b) { return a + b; })publicintSum(inta, intb) =>a+b;
// properties (same as Length { get { return End – Start; } })publicstringLength=>End-Start;
nameof()
publicvoidM() {}
publicvoidX() {
// Good for refactoring, compiler-verified:Console.WriteLine(nameof(M)); // => M
}
is actually the same as
because when person.Name is null it will also use "(Unknown)"