Skip to content

Commit 86eec38

Browse files
authored
FormattableString F# snippets (#7728)
1 parent 124fd40 commit 86eec38

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
open System
2+
3+
let name = "Fred"
4+
// <Snippet9>
5+
String.Format("Name = {0}, hours = {1:hh}", name, DateTime.Now)
6+
// </Snippet9>
7+
|> ignore
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="Composite1.fs" />
9+
</ItemGroup>
10+
</Project>

xml/System/FormattableString.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,26 @@
166166
167167
### Remarks
168168
169-
This static method may be imported in C# by:
169+
This static method may be imported in C# or F# by:
170170
171171
```csharp
172172
using static System.FormattableString;
173173
```
174174
175+
``fsharp
176+
open type System.FormattableString
177+
```
178+
175179
Within the scope of that import directive, an interpolated string may be formatted in the current culture by writing, for example:
176180
177181
```csharp
178182
CurrentCulture($"{{ lat = {latitude}; lon = {longitude} }}");
179183
```
180184
185+
```fsharp
186+
CurrentCulture $"{{ lat = {latitude}; lon = {longitude} }}"
187+
```
188+
181189
]]></format>
182190
</remarks>
183191
</Docs>
@@ -223,6 +231,7 @@ Within the scope of that import directive, an interpolated string may be formatt
223231
A composite format string consists of zero or more runs of fixed text intermixed with one or more format items, which are indicated by an index number delimited with brackets (for example, `{0}`). The index of each format item corresponds to an argument in an object list that follows the composite format string. For example, in the following statement:
224232
225233
:::code language="csharp" source="~/snippets/csharp/System/FormattableString/Format/Composite1.cs" id="Snippet9":::
234+
:::code language="fsharp" source="~/snippets/fsharp/System/FormattableString/Format/Composite1.fs" id="Snippet9":::
226235
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Formatting.Composite/vb/Composite1.vb" id="Snippet9":::
227236
228237
the composite format string is `"Name = {0}, hours = {1:hh}"`.

0 commit comments

Comments
 (0)