diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs new file mode 100644 index 00000000000..61abb4bd791 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs @@ -0,0 +1,63 @@ +open System + +let useCharEnumerator() = + // + let title = "A Tale of Two Cities" + let chEnum = title.GetEnumerator() + + printfn $"The length of the string is {title.Length} characters:" + + let mutable outputLine1 = "" + let mutable outputLine2 = "" + let mutable outputLine3 = "" + let mutable i = 1 + + while chEnum.MoveNext() do + outputLine1 <- outputLine1 + if i < 10 || i % 10 <> 0 then " " else $"{i / 10} " + outputLine2 <- outputLine2 + $"{i % 10} "; + outputLine3 <- outputLine3 + $"{chEnum.Current} " + i <- i + 1 + + printfn "%s" outputLine1 + printfn "%s" outputLine2 + printfn "%s" outputLine3 + + // The example displays the following output to the console: + // The length of the string is 20 characters: + // 1 2 + // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 + // A T a l e o f T w o C i t i e s + // + +let useForEach () = + // + let title = "A Tale of Two Cities" + let chEnum = title.GetEnumerator() + + printfn $"The length of the string is {title.Length} characters:" + + let mutable outputLine1 = "" + let mutable outputLine2 = "" + let mutable outputLine3 = "" + let mutable i = 1 + + for ch in title do + outputLine1 <- outputLine1 + if i < 10 || i % 10 <> 0 then " " else $"{i / 10} " + outputLine2 <- outputLine2 + $"{i % 10} "; + outputLine3 <- outputLine3 + $"{ch} " + i <- i + 1 + + printfn "%s" outputLine1 + printfn "%s" outputLine2 + printfn "%s" outputLine3 + + // The example displays the following output to the console: + // The length of the string is 20 characters: + // 1 2 + // 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 + // A T a l e o f T w o C i t i e s + // + +useCharEnumerator () +printfn "-----" +useForEach () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/fs.fsproj new file mode 100644 index 00000000000..fee390d0daa --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/xml/System/CharEnumerator.xml b/xml/System/CharEnumerator.xml index 077d241f6ae..464955f0519 100644 --- a/xml/System/CharEnumerator.xml +++ b/xml/System/CharEnumerator.xml @@ -92,12 +92,14 @@ :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cs/CharEnumerator1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cs/CharEnumerator1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: ]]> @@ -223,12 +225,14 @@ :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cs/CharEnumerator1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cs/CharEnumerator1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: ]]> @@ -342,12 +346,14 @@ :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cs/CharEnumerator1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cs/CharEnumerator1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: ]]>