c # $ symbol character problems connected with the ternary operator

Write code encountered such a problem, the $ symbol string processing ternary operator with little problems occurred together, as follows:

 1 using System;
 2 namespace HelloWorld
 3 {
 4     class Program
 5     {
 6         static void Main(string[] args)
 7         {
 8             bool b = true;
 9             string who = b ? "Tom" : "Jerry";
10             Console.WriteLine($"Hello {who}");
11             Console.ReadLine();
12         }
13     }
14 }

The code above without any problems, but if the merger line 9 and the tenth row,

 1 using System;
 2 namespace HelloWorld
 3 {
 4     class Program
 5     {
 6         static void Main(string[] args)
 7         {
 8             Console.WriteLine($"Hello {b ? "Tom" : "Jerry"}");
 9             Console.ReadLine();
10         }
11     }
12 }

The interpolation expression can not have colons, parentheses must:

Console.WriteLine($"Hello {(b ? "Tom" : "Jerry")}");

I do not know why the expression can not be interpolated by a colon.

Guess you like

Origin www.cnblogs.com/Forlight/p/11872230.html