-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1649 from vfp9/main
Simultaneous update of Simplified Chinese documentation
- Loading branch information
Showing
4 changed files
with
42 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?xml-stylesheet type="text/xsl" href="../helpproject.xsl" ?> | ||
<topic template="Default" modified="2024-12-04T00:07:55.077+08:00" lasteditedby="niuji" version="2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../helpproject.xsd"> | ||
<title>__InterpolatedStrings</title> | ||
<body> | ||
<header> | ||
<para styleclass="Heading1">__InterpolatedStrings</para> | ||
</header> | ||
<para styleclass="Normal">插值字符串是一种允许将局部变量、实例变量或其他表达式嵌入字面字符串的功能。X# 支持两种插值字符串:</para> | ||
<para styleclass="Normal"></para> | ||
<para styleclass="Heading2"><text style="font-weight:bold;">1.</text><tab /><text style="font-weight:bold;">常规插值字符串: i"...."</text></para> | ||
<para styleclass="Normal"><tab /></para> | ||
<para styleclass="Normal">其工作方式与普通 X# 字符串类似,内嵌表达式:</para> | ||
<para styleclass="Normal"></para> | ||
<para styleclass="Code Example"><tab /><text style="font-weight:bold; font-style:normal; color:#3366ff;">FUNCTION</text><text style="font-weight:normal; font-style:normal; color:#000000;"> Start </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">AS</text><text style="font-weight:normal; font-style:normal; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">VOID</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">LOCAL</text><text style="font-weight:normal; font-style:normal; color:#000000;"> Who </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">AS</text><text style="font-weight:normal; font-style:normal; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">STRING</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Who := </text><text style="font-weight:bold; font-style:normal; color:#993366;">"World"</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Console.Writeline( i</text><text style="font-weight:bold; font-style:normal; color:#993366;">"Hello {Who}"</text><text style="font-weight:normal; font-style:normal; color:#000000;">)</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Console.Read()</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">RETURN</text></para> | ||
<para styleclass="Heading2">2.<tab />扩展插值字符串: ie"..." 和 ei"...."</para> | ||
<para styleclass="Normal">这是插值字符串和扩展字符串的组合。在下面的示例中,\t 将被 tab 字符替换:</para> | ||
<para styleclass="Normal"></para> | ||
<para styleclass="Code Example"><text style="font-weight:normal; font-style:normal; color:#000000;">   </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">FUNCTION</text><text style="font-weight:normal; font-style:normal; color:#000000;"> Start </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">AS</text><text style="font-weight:normal; font-style:normal; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">VOID</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">LOCAL</text><text style="font-weight:normal; font-style:normal; color:#000000;"> Who </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">AS</text><text style="font-weight:normal; font-style:normal; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">STRING</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Who := </text><text style="font-weight:bold; font-style:normal; color:#993366;">"World"</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Console.Writeline( ie</text><text style="font-weight:bold; font-style:normal; color:#993366;">"Hello\t{Who}"</text><text style="font-weight:normal; font-style:normal; color:#000000;">)</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Console.Read()</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">RETURN</text></para> | ||
<para styleclass="Heading2">注意:</para> | ||
<para styleclass="" style="text-align:left; text-indent:0px; margin-top:0px; margin-right:0px; margin-bottom:0px; margin-left:0px; line-height:1.00; background-color:transparent; white-space:normal; page-break-inside:auto; page-break-after:auto; border:none; tabstops:none;"><text styleclass="" style="font-family:Arial; font-size:10pt; color:#000000;">X# 内的插值字符串可以包含以下形式的表达式</text></para> | ||
<para styleclass="Code Example"><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#3366ff;">{<interpolationExpression>[,<alignment>][::<formatString>]}</text></para> | ||
<para styleclass="Body Text">在 C# 中,formatString 的前缀是单冒号。请注意,由于在 X# 中,冒号(:)操作符是实例字段、属性和方法的默认成员访问操作符,因此并不总是可以使用该操作符来分隔表达式和格式字符串。因此,我们将该操作符改为双冒号(::)。如果使用 /allowdot+ 进行编译,也可以使用单冒号作为格式分隔符。</para> | ||
<para styleclass="Body Text"></para> | ||
<para styleclass="Body Text">要表示字面上的“{”或“}”字符,必须在字符串中复制它们。本例中字符串内的表达式用斜体表示。</para> | ||
<para styleclass="Code Example"><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;">  </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">FUNCTION</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;"> Start() </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">AS</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">VOID</text><br/><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;">   </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">local</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;"> X := 2 </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">as</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">INT</text><br/><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;">   </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">local</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;"> Y := 3 </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">as</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">INT</text><br/><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;">   </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">var</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;"> pointMessage := i</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#3366ff;">"The point {{{</text><text style="font-weight:bold; font-style:italic; text-decoration:none; color:#3366ff;">X</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#3366ff;">}, {</text><text style="font-weight:bold; font-style:italic; text-decoration:none; color:#3366ff;">Y</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#3366ff;">}}} is {</text><text style="font-weight:bold; font-style:italic; text-decoration:none; color:#3366ff;">Math.Sqrt(X * X + Y * Y)</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#3366ff;">::F3} from the origin"</text><br/><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;">   </text><text style="font-weight:bold; font-style:normal; text-decoration:none; color:#ff0000;">Console</text><text style="font-weight:normal; font-style:normal; text-decoration:none; color:#000000;">.WriteLine(pointMessage)</text><br/><tab /><text style="font-style:italic; text-decoration:none; color:#339966;">// 输出结果:</text><br/><tab /><text style="font-style:italic; text-decoration:none; color:#339966;">// The point {2, 3} is 3.606 from the origin</text></para> | ||
<para styleclass="Body Text"></para> | ||
<para styleclass="Normal">字符串内的表达式元素可以使用格式化符号,就像 String.Format() 符号一样。例如:</para> | ||
<para styleclass="Normal"></para> | ||
<para styleclass="Code Example"><tab /><text style="font-weight:bold; font-style:normal; color:#3366ff;">FUNCTION</text><text style="font-weight:normal; font-style:normal; color:#000000;"> Start </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">AS</text><text style="font-weight:normal; font-style:normal; color:#000000;"> </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">VOID</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">LOCAL</text><text style="font-weight:normal; font-style:normal; color:#000000;"> i </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">AS</text><text style="font-weight:normal; font-style:normal; color:#000000;"> INT</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      i := 42</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Console.Writeline( i</text><text style="font-weight:bold; font-style:normal; color:#993366;">"Hello {i:x}"</text><text style="font-weight:normal; font-style:normal; color:#000000;">)   </text><text style="font-weight:normal; font-style:italic; color:#339966;">// i 用十六进制表示,所以输出 Hello 2a</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">      Console.Read()</text><br/><text style="font-weight:normal; font-style:normal; color:#000000;">     </text><text style="font-weight:bold; font-style:normal; color:#3366ff;">RETURN</text></para> | ||
</body> | ||
</topic> |
Oops, something went wrong.